PortiBlog

Updating a multi-people field in SharePoint with Microsoft Flow

3 september 2018

If you want to update an item/document metadata in SharePoint with Flow, the Update Item / Update File Properties action is your saviour. Or isn't it?

I stumbled upon a call for help on Twitter from Vlad Catrinescu (@vladcatrinescu) where he asked how to update a People field with multi-select option enabled. I went to create a list in my test environment with that fieldtype and when I looked into the Update Item action in Microsoft Flow, I saw that that field was not available.

The only option that came to mind was using the Send an HTTP Request to SharePoint action, so I started looking into updating a People field by using the REST API. I found out that you can update a People field with the REST API, but you have the use the User Principal ID for that.


{
    "__metadata": { type: "" },
    Target_x0020_fieldId: { 'results': <id's>}
}

I will get into more details about the entity type later.

Because you can't get the User ID directly in Flow (you only get Claims, Department, DisplayName, Email, JobTitle and Picture) it meant that I had to use two Send an HTTP Request to SharePoint actions:

  • One for getting the User ID
  • One for updating the item

For this example, I'll be using data from the Created By and Modified By fields to update my People field (which is 'Target field'), but you can also use any other fields that have a email address in it. Please contact me if you need any help with this.

Get the User IDs

The HTTP endpoint for getting user information is as follows:

<code><strong><em>&lt;siteUrl&gt;</em></strong>/_api/web/SiteUsers/getByEmail('<em><strong>&lt;email&gt;</strong></em>')</code>

All you have to do is to add the Send an HTTP Request to SharePoint action and fill in your site address and your Uri, which is the above endpoint. You need to replace the <email> string with the email address of the user you want to use. You can use the Dynamic Attribute for 'Created by Email' for this.

This action will provide you with an array of information of that specific user. All you need to do is to extract the id property. You can do this by initializing a variable and set its value to the id attribute from your HTTP response.

body('<name of your action>')['d']['id']

Please note that your user has be a known user within your site collection. If you're user hasn't been added to the sitecollection yet, this won't work.

Because I want both Creator and Editor to be put into my Target field, I have to configure these two actions for my Modified By field as well.

Now we have two User ID's, but before we can update the item, we have to put them both together so they can be used in the call. The endpoint expects the following format

[<id1>, <id2>, <etc.> ]

To achieve this, we can use the Compose action:

Update your People field

Before we can put together our final Send an HTTP Request to SharePoint action, we need to find our the entity type of our listitem which we need in the body of our request. You can easily find this by navigating to the following url:

<siteUrl>/_api/lists/getbytitle('<listName>')?$select=ListItemEntityTypeFullName

You will see an XML output your browser, in which you should be looking for the entry named '<d:ListItemEntityTypeFullName>'. In my case, the entity type was named 'SP.Data.PeopletestListItem'.

With this information, we can put together our final Send an HTTP Request to SharePoint action, which is a PATCH call to the following endpoint:

<siteUrl>/_api/lists/getByTitle('<listName>')/items(<ID>)

The action needs three headers:

  • Accept: application/json;odata=verbose
  • Content-Type: application/json;odata=verbose
  • IF-MATCH: *

And its body is the one I stated above. With the Site Address, Method, Uri, Headers and the body filled, it looks like:

After running the Flow, you will see that the Target field has been successfully updated with the Creator and the Editor:

Sourcehttps://www.about365.nl/2018/08/06/updating-a-multi-people-field-in-sharepoint-with-microsoft-flow/

Submit a comment