Question

How to add lookup value (Title ) column "achat" : lookup field

enter c
if (itemEnum.moveNext()) {
    // update the item
    var current = itemEnum.get_current();
    // add lookup field  
    var lkfieldsomthing = new SP.FieldLookupValue();
    var Name = $("#txt").val();
    lkfieldsomthing.set_lookupValue(Name);
    current.set_item('achat', lkfieldsomthing);
    current.update();
    clientContext.load(current);
    clientContext.executeQueryAsync(
        function(sender, args) {
              // handle successful update
        },
        function(sender, args) {
             // handle error
       });
}
Was it helpful?

Solution

In SharePoint JSOM, following is the correct way to set the lookup column in list:

var lkfieldsomthing = new SP.FieldLookupValue();  
lkfieldsomthing.set_lookupId(Lookup_ID);  
current.set_item('InternalNameOfLookupField', lkfieldsomthing);
current.update();

Where:

  1. Lookup_ID : The unique, SharePoint default ID of the list item from where your are referencing your lookup(Source/Provider List).

  2. InternalNameOfLookupField : Internal name of lookup field in your Destination/Consumer list.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top