Reputation: 43
I am using the Microsoft Graph API (Beta) to update SharePoint ListItems. However, I am failing to change the value of a 'Person or Group' column. The column has the attribute 'Allow multiple selections' and accepts both persons and groups. This is how it looks like as part of the ListItem columnSet:
{
"AssignedTo": [
{
"Email": "[email protected]",
"LookupId": 123,
"LookupValue": "User Name"
}
]
}
Updating the value of columns other than 'Person or Group' is working fine: As documented, I am sending a PATCH request to the ListItem's columnSet. The request header contains the content type 'application/json' and the request body contains a JSON-encoded dictionary of column names and their (new) values:
{
"RegularColumn": "new value"
}
I have experimented quite a bit with using the user's id, email and/or name, but all I get is this error: 'The request is malformed or incorrect.'
How can I update the value of a 'Person or Group' column? How would a sample JSON request body look like?
Thanks for any suggestions!
Upvotes: 4
Views: 4438
Reputation: 11
After lot of tinkering around I managed to find solution to this through use of msgraph, without having to switch back to sharepoint v1.0 api. Solution:you can pull the user's list using displayName: "User Information List"
example: GET https://graph.microsoft.com/v1.0/groups/{group-id}/sites/root/lists/User Information List/ (This contains the lookup ids for users. Also, in other words, this is the list being used by personOrGroup column for lookups)
In case of a new entry, similarly, you will first need to add to above list a new listItem in usual way and then use that new created id to set LookupField as suggested above in answer.
Upvotes: 0
Reputation: 758
I have been looking for a solution to the same issue for quite a while and did not find any solutions on StackOverflow or the web. Thanks to the post from Vadim Gremyachev (See the related question regarding fields of type 'lookup' here), I was able to successfully update a field of type 'personOrGroup' with the activated setting 'allowMultipleSelection' via the Graph Api. You can update single value 'personOrGroup' fields, by combining the field name with LookupId and passing the LookupId as the value:
{
"AssignedToLookupId":"123"
}
If you want to update a multi value 'personOrGroup' fields, you need to specify the data type first and pass the ids as an array:
{
"[email protected]":"Collection(Edm.String)",
"AssignedToLookupId":["123", "124"]
}
Upvotes: 3
Reputation: 5081
I think I found a workaround how to make it instead of Graph: use the sharepoint rest api for creating/updating multiple 'Person or Group'
field instead of Graph api
using AAD Client (ADAL.js) with connection to Application in your AAD. It works both for SPFx webpart and Azure Functions. But anyway, pity that officially there is no info from microsoft.
Upvotes: 0