none
Set multiple people picker value using REST API RRS feed

  • Question

  • I have the javascript code working where I have the list of users in an array called "UserIds". But I am getting error below, when I am making the REST call for posting the data.

    "A 'PrimitiveValue' node with non-null value was found when trying to read the value of a navigation property; however, a 'StartArray' node, a 'StartObject' node, or a 'PrimitiveValue' node with null value was expected.\"}}}","status":400,"statusText":"Bad Request"}

    createListItemWithDetails: function(listName, userIds, success, failure) {

            CUSTOMFORMCODE.getItemTypeForListNameviaREST(listName).then(
                function(itemType) {
                       
                    var item = {
                        "__metadata": { "type": itemType },
                        "elvlglENotificationId": {"results":userIds} //Is this right??
                    };
                  
                                 var siteurl = _spPageContextInfo.webAbsoluteUrl;

                    jQuery.ajax({
                        url: siteurl + "/_api/web/lists/getbytitle('" + listName + "')/items",
                        type: "POST",
                        contentType: "application/json;odata=verbose",
                        data: JSON.stringify(item),
                        headers: {
                            "Accept": "application/json;odata=verbose",
                            "X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
                        },
                        success: function (data) {
                       alert("Success");
                            success(data, false);
                        },
                        error: function (data) {
                       alert("Error: "+ JSON.stringify(data));
                       
                            failure(data, true);
                        }
                    });
                   
                });
        },


    ViviSP

    Sunday, August 4, 2019 6:12 AM

All replies

  • Hi ViviSP,

    To set value People picker field in list using REST API

    var addNewItemUrl = "/_api/Web/Lists/GetByTitle('SpTest')/Items"; 
    
    var data = {
        __metadata: { 'type': 'SP.Data.SpTestListItem' },
        AuthorId: 3,
    };
    
    addNewItem(addNewItemUrl,data);
    
    function addNewItem(url, data) {
        $.ajax({
            url: _spPageContextInfo.webAbsoluteUrl + url,
            type: "POST",
            headers: {
                "accept": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                "content-Type": "application/json;odata=verbose"
            },
            data: JSON.stringify(data),
            success: function (data) {
                console.log(data);
            },
            error: function (error) {
                alert(JSON.stringify(error));
            }
        });
    }

    Note: For multi value people picker column pass int array inside people piker field.

    URL: SiteURL + /_api/web/lists/getbytitle('List Display Name')/items?$expand=Author&$select=Author/Id,Title
    Thanks & Regards,



    sharath aluri

    Sunday, August 4, 2019 7:07 PM
  • Hi,

    To update multiple user field by rest api, the user IDs should be like below.

    data: { "__metadata": { "type": "SP.Data.ListNameListItem" }, "Title": "Second Item", "PeopleFieldId": { "results": ["4", "7"] } };

    Here is the thread for your reference.

    http://sharepoint.sureshc.com/2016/05/how-to-update-person-field-with-multiple-values-using-rest-api.html

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, August 5, 2019 2:13 AM