7

When adding a new item to list via the Sharepoint 2013 REST API I want to populate one of its multi-value lookup columns.

I've tried passing in an array of Ids or a string with separators but nothing seems to work.

11

I'm hoping your question was for a multi-select choice field, where the entries are simply text, not referring items in another list. I was able to guess the answer from this microsoft article

If you look under the ListItemCollection resource for "POST request example: Create list item" they show the following:

method: "POST",
body: "{ '__metadata': { 'type': 'SP.Data.Team_x0020_tasksListItem' },
    'Title': 'Teams incorporate feedback', 'AssignedToId': {"results":[1]},
    'StartDate':'2014-01-29T08:00:00Z', 'DueDate':'2014-01-31T08:00:00Z',
    'PredecessorsId': {"results":[4]} }",

The PredecessorId field is using the format you need for a multiple select field.

Generalized:

'<multi-select column name>': {"results":["<text of first selection to set>", "<text of second selection to set>", ...]}

If you wanted to clear all selections:

'<multi-select column name>': {"results":[]}
  • I've been looking all over for this answer. Thanks kimon! +1 – Mike Apr 8 '14 at 18:50
  • +1. Just a note, in my case the type property in __metadata had to be correct. You get the type either __metadata.type from an item or from ListItemEntityTypeFullName on the list. – eirikb Jan 26 '15 at 6:23
4

Don't forget to put "Id" at the end of your column name. For example: if your column name is 'AssignedTo' you have to put 'AssignedToId'

Also make sure the ID's you are providing in the "results" array are int's and not strings.

  • 1
    PLUS 1: this was killing me (appending Id to the field name for the POST) – hitdrumhard Aug 1 '14 at 20:36
0

Here i update the list(dynamic list) by pass the users id into sharepoint person or group field column(Approver1) using array.

var arry=[10,15];
$.ajax  
        ({  
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('dynamiclist')/items", 
        type: "POST",  
        data: JSON.stringify  
        ({  
            __metadata:  
            {  
                type: "SP.Data.DynamiclistListItem"  
            },  
            Employeename:"Test" ,   //replace your column name
            Approver1Id:{results:arry} //column name Approver1 added with Id
        }),  
        headers:  

        {  
            "Accept": "application/json;odata=verbose",  
            "Content-Type": "application/json;odata=verbose",  
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),  
            "X-HTTP-Method": "POST"  
        },  
        success: function(data, status, xhr)  
        {  
             alert("ok");
        },  
        error: function(xhr, status, error)  
        {  
alert();
        }  
    });  

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.