Adding Multiple value to lookup field via REST

             var itemProperties = {
                ‘__metadata’: { “type”: “SP.Data.QuestionsListItem” },
                ‘AnsChoicesId’: { “results”: [1,3] }  //multi-valued User field value 
            };

            $.ajax({

                url: appweburl + “/_api/web/lists/GetByTitle(‘ListTitleGoesHere’)/items(“+ListItem+”)”,
                type: “MERGE”,
                data: JSON.stringify(itemProperties),
                headers: {
                    “X-RequestDigest”: $(“#__REQUESTDIGEST”).val(),
                    “accept”: “application/json; odata=verbose”,
                    “If-Match”: “*”,
                    “content-type”: “application/json;odata=verbose”
                }
            }).done(function () {
                console.log(“Done”);
            }).fail(function () {
                console.log(“FaiL”);
            });


In the above code all of the array items will be replaced with the item ID’s specified. 

//code coming soon

Here is what adding Multiple values looks like in JSOM (This example is create a new record, not updating a record)

var clientContext = SP.ClientContext.get_current();
            var oList = clientContext.get_web().get_lists().getByTitle(‘ListTitleGoesHere’);
            var itemCreateInfo = new SP.ListItemCreationInformation();
            oListItem = oList.addItem(itemCreateInfo);
            oListItem.set_item(‘Title’, ‘HelloThisStuffWorld’);
            var lookupsIds = [1, 2, 3];
            var lookups = [];
            for (var ii in lookupsIds) {
                var lookupValue = new SP.FieldLookupValue();
                lookupValue.set_lookupId(lookupsIds[ii]);
                lookups.push(lookupValue);
            }
            oListItem.set_item(‘AnsChoices’, lookups);
            oListItem.update();
            clientContext.load(oListItem);
            clientContext.executeQueryAsync(
         function () { alert(“Success!”) },
         function () { alert(“Request failed”) }

        );

Leave a Reply

Your email address will not be published. Required fields are marked *