Updating a multi-people field in SharePoint with Microsoft Flow

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: "<entity 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:

<siteUrl>/_api/web/SiteUsers/getByEmail('<email>')

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:

14 Replies to “Updating a multi-people field in SharePoint with Microsoft Flow”

  1. Hello,

    I am very glad I found this post, thank you for writing it! I am hoping you can help me clean up my own json as I’m running into errors. First it was the same Primitive Value one as Kalyan above, but now I am running into trouble getting my column to be recognized in the json you provided to kalyan.

    So I am trying to update a People Picker field using an https request (the update item won’t work since we don’t use email through Microsoft). I have replaced your json above with some of my own fields/info. The issue is that the column name isn’t being recognized and I’m getting a “Invalid JSON. The property name ” is not valid. The name of a property cannot be empty.” error. My column is named “Previous User(s)” which includes the s in parentheses (and it’s too late to really change it).

    I have tried using that name in both single and double quotes and with both ID and Id at the end to no avail. I’ve also tried the shorter version of the SP column name (can’t remember what it’s called) and the longer version with and without quotes (single and double), as well as with ID and without.

    Shorter: Previous_x0020_Owner_x0020_or_x0
    Longer: Previous_x005f_x0020_x005f_Owner_x005f_x0020_x005f_or_x005f_x0

    {
    “_metadata”: { type: “SP.Data.RSC_x0020_Device_x0020_InventoryListItem” },
    “Previous User(s)ID”: {@{items(‘Apply_to_each_2’)?[‘Id’]}}
    }

    I am unsure of how to get this field updated, but any help would be greatly, greatly appreciated!!!

    Thank you!

    note: apologies if this is a duplicate post, I can’t find the first one.

    0
    0
    1. Column names can be a real pain sometimes. You should use the internal (probably shortened) column name. You can find it by going a GET request to your list: /_api/web/lists(‘‘)/items. You will get all items from your list, including all internal fieldnames. Just search for something like ‘previous’ and I’m sure you will find it. That internal name can then be used in your POST request to update the field value.

      0
      0
  2. Rik, how would I accomplish the following goal?

    – User manually enters 2 or 3 known email addresses in a Contacts field on a MS Form.
    – Power Automate flow sends all the email addresses to a SharePoint Person or Group multi-select field
    – SharePoint list displays these multiple Names w Presence in the Contacts column.

    I have been able to replicate this with one email address entered, but I’m not sure how to enter multiple emails in that field, as I could do directly in SharePoint. I’ve tried separating with comas, spaces and semi-colons.

    Any ideas?

    0
    0
    1. I think you’re on the right track by using a separator. You can then split your string from your Form in your flow by using the split() expression and then use an Apply to each to go through the array and use the method as described in this blogpost.
      The thing is that the separator needs to be manually provided so it’s very error-sensitive.

      0
      0
  3. Worked perfectly fine. I missed appending Id to the target column name.

    Awesome article and worked for me.

    0
    0
  4. I have followed the exact steps as you listed above. but I get the following error when I run my flow at HTTP PATCH . Please advise how to resolve this or what to look for.

    {
    “status”: 400,
    “message”: “A node of type ‘PrimitiveValue’ was read from the JSON reader when trying to read the entries of a feed. A ‘StartObject’ or ‘EndArray’ node was expected.\r\nclientRequestId: 82dbc29a-fb93-41eb-80d4-3572e9d2c4b4\r\nserviceRequestId: 7e07549f-9093-a000-87a0-f2085b3b9064”,
    “source”: “/_api/lists/getByTitle(‘Part%20ID%20Tasks’)/items(77)”,
    “errors”: [
    “-1”,
    “Microsoft.SharePoint.Client.InvalidClientQueryException”
    ]
    }

    0
    0
    1. Your HTTP request body seems to be incorrect. Please make sure your body is in the correct format:

      {
      “_metadata”: { type: “” },
      Id: {[AuthorXId, AuthorYId, AuthorZId]}
      }

      Where , and AuthorXId need to be configured according to your environment

      0
      0
  5. Hi, Thank you for this post. However, how to add a user to a Person/user field in a list, if the user has never been added to the site?

    0
    0
    1. You’re right. My solution only covers existing users on a site.
      If you have a non-existing user, you should add it to your site first. Unfortunately, I don’t know the API call for this

      0
      0
    2. To add a user to the site, please use the ensure User function. It will return the site Id for the user.

      0
      0

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.