Chris Hopkins' Blog - #makinitdostuff

The place where I post information about the products I manage; SharePoint, Yammer, Project and Visio and maybe from some that I don't!

Setting AssignedToId from JavaScript / JSON

Setting AssignedToId from JavaScript / JSON

Rate This
  • Comments 1

Maybe someone already blogged about this but I could not find it.

I needed to create new tasks in a tasks list on my SharePoint 2013 site but I could not get it to accept a value for the AssignedToId as I wanted to not only create the task but also assign it to the appropriate people.

This field is a multi-value field where multiple people can be assigned to the task.  He you have to provide a JSON array of user IDs.

// add new task to task list
var requestUri = _spPageContextInfo.webAbsoluteUrl +
          "/_api/Web/Lists/getByTitle('Test Tasks')/items/";

var requestHeaders = {
    "accept": "application/json;odata=verbose",
    "X-RequestDigest": $("#__REQUESTDIGEST").val(),

var requestData = {
    __metadata: { "type": "SP.Data.Test_x0020_TasksListItem" },
    'Title': “Do something" productive”,
    'Body': “Do something productive and help the team succeed”,
    'AssignedToId': {"results":[11]}, // user id
    'DueDate': “12/30/2013”

var requestBody = JSON.stringify(requestData);

    url: requestUri,
    type: "Post",
    contentType: "application/json;odata=verbose",
    headers: requestHeaders,
    data: requestBody,
     success: onSuccess,
    error: onError

Leave a Comment
  • Please add 3 and 5 and type the answer here:
  • Post
Page 1 of 1 (1 items)