how to add lookup value sharepoint online
-
05-02-2021 - |
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
});
}
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:
Lookup_ID
: The unique, SharePoint default ID of the list item from where your are referencing your lookup(Source/Provider List).InternalNameOfLookupField
: Internal name of lookup field in your Destination/Consumer list.
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange