Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

how to add user to sharepoint list item user field using REST api in sp2013?

$
0
0

Hi,

I have a basic sharepoint list with people field in it, now I am trying to use rest api to add new list item and trying to set person field to my alias but it is not working and throwing me below error. looks like it is problem with how my user data is passed but I could not able to find any help online.

can you guys help with the correct way to make this call, any help is greatly appreciated.

function runAjax(){ 
   var d  = JSON.stringify({"__metadata":{"type":"SP.Data.RepositoryItem"},"Owners":"-1;#v-mynme@microsoft.com"});
    jQuery.ajax({ 
        url: "https://microsoft.sharepoint.com/sites/mysite/docstore/_api/web/lists/GetByTitle('Repository')/items(1580) ",
        type: "POST", 
        headers: { "accept": "application/json;odata=verbose", "content-type": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val(), "X-HTTP-Method": "MERGE", "If-Match": "*" 
        }, 
        data:d, 
        success: function (_a) { 
            console.log(JSON.stringify(_a)); 
        }, 
        error: function (_e) { 
            console.error(JSON.stringify(_e)); 
        } 
    }); 
} 
runAjax();

error I am getting is

Updation fail{"readyState":4,"responseText":"{\"error\":{\"code\":\"-1, Microsoft.SharePoint.Client.InvalidClientQueryException\",\"message\":{\"lang\":\"en-US\",\"value\":\"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"} 


Naresh Bojja http://nareshbojja.wordpress.com


Viewing all articles
Browse latest Browse all 25064

Trending Articles