0

I found myself in an unfortunate position of being unable to use SharePoint Designer to build workflows and thus am having to rebuild an approval workflow in JavaScript. I am using REST to insert a new task item but need to expand it to assign the task to all users in a group and make it so that whoever in the group is the first to approve or reject the task will set the task status.

Do I simply need to replace the userId in AssignedToId: userId with groupId? Or would I use the REST API to GET a list of users (and their IDs) from the group name using url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups/getbyname('" + strSPGroupName + "')/users" and then create an array of the user ids for use in this:

data: JSON.stringify({
    __metadata: { "type": "SP.Data.TasksListItem" },
    Title: "Sample Task",
    AssignedToId: { 'results': [11,22] },
    DueDate: due,
    Status: "In Progress"
})

I have my Task list AssignedTo column set to Allow Multiple Selections: Yes and Allow Selection Of: People and Groups

1

You are missing the "__metadata" property from the "AssignedToId" object: Try this out:

data: JSON.stringify({
    __metadata: { "type": "SP.Data.TasksListItem" },
    Title: "Sample Task",
    AssignedToId: { "__metadata": { "type": "Collection(Edm.Int32)"},'results': [11,22] },
    DueDate: due,
    Status: "In Progress"
})
  • Thanks for the clarification on the _metadata property. Any thoughts on how it would look if I wanted to assign a task to a group, rather than an individual? – BWieland86 Apr 29 at 13:49
  • 1
    It is the same method, replace the UserIds with GroupIds, the ids of groups and people are unique. – Bálint Apr 29 at 13:58
  • Awesome, thanks! – BWieland86 Apr 29 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.