web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Nishant Rana’s Weblog / Set AssignedToId for a List...

Set AssignedToId for a ListItem using SharePoint 2013 Rest API.

Nishant Rana Profile Picture Nishant Rana 11,325 Microsoft Employee

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.


Filed under: SharePoint, SharePoint 2013 Tagged: SharePoint, SharePoint 2013

This was originally posted here.

Comments

*This post is locked for comments