1

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
       });
}
1
  • Are you getting any error? If Yes, please post the error here Commented Feb 11, 2019 at 12:51

1 Answer 1

3

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. You can get the internal name of your lookup column by following this article: How to find the Internal name of columns in SharePoint Online?

5
  • I'm going to add the input value in a lookup column ?? var Name = $("#txt").val();
    – NOOR
    Commented Feb 11, 2019 at 14:55
  • Free text will not get added in the lookup field. To set the lookup field you need to save the ID of the list item from where your are referencing your lookup(Source/Provider List). Commented Feb 11, 2019 at 14:58
  • Are you using custom html form? Commented Feb 11, 2019 at 15:00
  • I used the following html tag : <input title=" Client" id="Clients" style="border:none" />
    – NOOR
    Commented Feb 11, 2019 at 15:04
  • You cannot use the free text for lookup columns. You need to use the select tag and bind the list items IDs as a value to each option in your select tag. Commented Feb 11, 2019 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.