Set AssignedToId for a ListItem using SharePoint 2013 Rest API.

Hi,

Was working on a requirement in which we had to create new listitems of task type and set the Assigned To field in it.

It wasn’t as straight forward as we thought. Finally this is what worked


var fieldUserValues = new Array();
 fieldUserValues.push(userIdForTask);

var item = {
 "__metadata": { "type": eventToSave.TaskTypeName },
 "Title": eventToSave.EventName,
 "StartDate": startDate,
 "DueDate": endDate,
 "Body" : eventToSave.Description,
 "Priority": eventToSave.TaskPriority,
 'AssignedToId': { "results": fieldUserValues },
 };
 executor.executeAsync(
 {
 url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + eventToSave.TaskName + "')/items?@target='" + hostweburl + "'",
 method: "POST",
 headers: {
 "accept": "application/json;odata=verbose",
 "content-type": "application/json;odata=verbose",
 "X-RequestDigest": $("#__REQUESTDIGEST").val()

 },
 body: JSON.stringify(item),
 success: function (data) { succeededInsert(data); },
 error: failedInsert
 }
 );

Hope it helps.


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

1 thought on “Set AssignedToId for a ListItem using SharePoint 2013 Rest API.”

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s