In this post, we are going to demonstrate how to create a Flow (using Power Automate) that updates a SharePoint people picker field using the “Send a HTTP request to SharePoint” action.
The Flow will update the following people picker fields
- Requester: will be set to modified by field
- Manager: will be set from requester manager in case the manager does not exist will set to empty
- Assigned To: this is a multiple value field; we will get the values from a multi value people picker field in another list. In case no values are retrieved. We will set to empty
Before we start, it is important to mention that when using REST API, the People and Group field will be returned as “FieldNameId”. The format for user field value:
- single-valued user field: ‘<user field name>Id’ : <user id>
- multi-valued user field: ‘<user field name>Id’ : { ‘results’: [<array of user ids>] }
To empty the fields
- single-valued user field: ‘<user field name>Id’ : -1
- multi-valued user field: ‘<user field name>Id’ : { ‘results’: [0] }
Initialize Variables
So now let us go to our Flow and start by creating the needed variables. Note that it is not necessary to create these variables, but it will make the Flow more readable and maintainable.
Get Requester Id
As mentioned, to update a people picker field we need the Id of the user. At the time of writing, Flow does not support a way to retrieve user Id, so we must get it using the Rest API.
We can use the following Rest API to get site user information:
- _api/web/SiteUsers/getByEmail(‘UserEmail‘)
Get Manager Id
Now let’s get the manager for the requester.
Get AssignedTo Id
Update Item – Set Requester, Manager, AssignedTo
Update item using Send an HTTP request to SharePoint action set as following:
- Method: Post
- Uri: _api/lists/getbytitle(‘@{replace(variables(‘ListTitle’), ‘ ‘, ‘%20′)}’)/items(@{int(triggerBody()?[‘ID’])})
- Headers:
{ "Accept": "application/json;odata=verbose", "Content-Type": "application/json;odata=verbose", "X-HTTP-Method": "MERGE", "IF-MATCH": "*" } Remove highlighted in case of add item
- Headers:
{ "__metadata": { "type": "SP.Data.@{replace(variables('ListName'),' ','_x0020_')}ListItem" }, "RequesterId": "@{variables('RequesterId')}", "ManagerId": "@{variables('ManagerId')}", "AssignedToId" : @{variables('AssignedCCId')} }