What is Multi Select Lookup field ?
A Multi select lookup column is a field in the SharePoint list whose values are retrieved from another List. Using a multi select lookup column, you can display a list of choices in a combo box or list box. Since the lookup column is multi select, you can choose more than one item in the list.
What is Multi Select Choice filed ?
A Multi select choice field in the SharePoint list is column type that is possible to have more than one choice at once.
Work around
In normal scenario when a Lookup field is updated, as we know item id of the lookup list should be saved against the lookup column, but when it comes to the Multi select lookup column it is different.
When the normal Choice filed is updated string choice should be saved against the choice column, but if it is a Multi select choice field, it is different.
By using blow shown rest endpoint, all the LookupMulti type columns in a particular SharePoint list can be retrieved.
{site Url}/_api/web/lists/getbytitle('List Name')/fields?$filter=TypeAsString eq 'LookupMulti'
Please consider the result
![]() |
1 Results for REST call |
Bellow shown image shows the type of the field which is in JSON object.
![]() |
2. Type of the column |
Blow shown image shows a item which is retrieved using mentioned rest api call.
{site Url}/_api/web/lists/getbytitle('List Name')/items
As it shown in the bellow image, Multi select lookup field is contained a object. That object has two attributes metadata and results. metadata contained another object and result contained int array.
![]() |
3. Retrieved result |
Now we will see how we should update Multi select lookup field and Multi select choice field using REST api.
If the Multi select lookup field needs to be updated, below shown object should be saved against the multi select lookup column.
"result" should be a int array, which contains the item ids of the lookup list.
var lookUpMultiItemObj = {
__metadata: { "type": "Collection(Edm.Int32)" },
results: [1,3]
};
listItem["Column Name"] = lookUpMultiItemObj
;
If the Multi select choice field needs to be updated, below shown object should be saved against the multi select choice column.
"result" should be a string array, which contains the choices of the field.
var choiceMultiItemObj = {
__metadata: { "type": "Collection(Edm.String)" },
results: ["Choice 2","Choice 4"]
};
__metadata: { "type": "Collection(Edm.String)" },
results: ["Choice 2","Choice 4"]
};
listItem["Column Name"] = choiceMultiItemObj;
![]() |
4. Real code sample
After completing aforementioned steps, by using a normal ajax POST request the relevant items can be updated.
Keep sharing the knowledge! :)
|
Thank you for this information. This helped me!
ReplyDelete