As part of my code to add /update the list items I was trying to set the value for a lookup field using ECMA script block. When I try to do it I got the error message: fnFailedAdd. Message:Invalid data has been used to update the list item. The field you are trying to update may be read only.
I was trying to set the lookup value with the below code:
var objCrrItem = ObjLstEnum.get_current();
Note: This works for a normal field but this field is Lookup Field
JSOM code to set lookup column value sharepoint 2013:
We must have to set the lookup field value with SP.FieldLookupValue() object.
The code snippet will be like as below:
var _objLkpField = new SP.FieldLookupValue();
The complete code will be like as below:
var objClntContext = new SP.ClientContext.get_current();
var objWeb = objClntContext.get_web();
var ObjLst = objWeb.get_lists().getByTitle(“Car Inventory”);
Little background / prerequisites to execute this script:
– Create 2 lists
– Primary List
– Car Inventory
– Create lookup field from car inventory list to primary list
With this code operation completed successfully.
Hope this helps!!!!
Download FREE SharePoint 2019 Installation PDF Guide
This FREE PDF contains, Steps by step guide to install SharePoint 2019 Preview, prerequisites, hardware and software new features. First impression to SharePoint Server 2019 new modern site, modern lists and modern document libraries.
You May Also like the Following SharePoint Online Tutorials:
About Krishna Vandanapu
I am Krishna.Vandanapu a SharePoint architect working in IT from last 12 years, I worked in SharePoint 2007, 2010, 2013, 2016 and Office 365. I have extensive hands on experience in customizing SharePoint sites from end to end. Expertise in SharePoint migration tools like Sharegate, Doc Ave and Metalogix. Migrated SharePoint sites from SharePoint 2007 to 2010 and 2010 to 2013 several times seamlessly. Implementing CSOM with Microsoft best practices. Spent quality time in configuring SharePoint application services like User Profile, Search, Managed Meta data services etc. Now exploring SharePoint Framework and SharePoint 2019
Your FREESharePoint Online Ebook is on its way to your Email Inbox. **************** You will get notification on FREE SharePoint online training, SharePoint webinars, Video Tutorial & also latest FREE PDF tutorials