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

  • I'm going to add the input value in a lookup column ?? var Name = $("#txt").val(); – Alice Feb 11 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). – Ganesh Sanap Feb 11 at 14:58
  • Are you using custom html form? – Ganesh Sanap Feb 11 at 15:00
  • I used the following html tag : <input title=" Client" id="Clients" style="border:none" /> – Alice Feb 11 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. – Ganesh Sanap Feb 11 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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