问题
My situation
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": "user@domain.com",
"LookupId": 123,
"LookupValue": "User Name"
}
]
}
What works
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"
}
What does NOT work
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!
回答1:
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:
{
"AssignedToLookupId@odata.type":"Collection(Edm.String)",
"AssignedToLookupId":["123", "124"]
}
回答2:
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.
来源:https://stackoverflow.com/questions/42701107/how-do-i-update-the-value-of-person-or-group-columns-in-sharepoint-lists-using-t