Get the user ID to update a people field in Microsoft SharePoint with Power Automate

PersonId Field needs to be set

Get the user ID to update a people field in Microsoft SharePoint with Power Automate

By:

Date:

A While back I wrote a post about Updating People Fields in SharePoint using Flow. On of the requirement is to get the user ID of the user that you want to set a field to.

Get the user ID of a SharePoint user

How do we get this field ID?

We will need to have the Id to set a people field. Note from my previous post that you want to set a field PersonID if your field is called Person.

Get the user ID of a SharePoint user

The hidden user list

You might remember the hidden user list post by Thomas Zimmergren.

You can get the items from the hidden user list in two different ways. Either use a REST API call or just use the Get Items action in flow. Whichever has your preference.

Get The hidden user list items

I’m now using the Get items action.

To Update the list item I’m using the REST API call. Why? Simply because I want my flows to be more generic. I need to be able to copy Flows between environments. This also means that I need to be able to soft copy rather than hard copy the SharePoint site url.

Updating the list item people field

The Get Items will give me an array of 1 users. I queried by email address and I know for sure that I will only get one item back. To make sure that I don’t get one of those annoying apply to each steps added I’m including a first function which will give me the first item in the array of users. The full expression for this is:

first(body('Get_items')?['value'])?['Id']

Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There’s a better way — and I can show you exactly what it looks like. I’m the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide. For over 30 years I’ve been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions. SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://staging.sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/ Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://staging.sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/ You can contact me using contact@staging.sharepains.com

8 responses to “Get the user ID to update a people field in Microsoft SharePoint with Power Automate”

  1. Sumit Valecha Avatar
    Sumit Valecha

    Hi Thanks for this useful post.. But this means that user at some point was or is part of the site.. But what if user has never visited or been added to site.. I have this scenario where it is not guaranteed that user is or was part of site

    1. Pieter Veenstra Avatar

      Hi Sumit,

      The problem is that you would need to have an ID to set the user. The user will have an ID as soon as it has been used in a people field. So not when the user has been on the site.

      I just tried manually in SharePoint to set a field to an unknown user and that added the entry in the hidden user list.

  2. kauravin Avatar

    Hi,
    Thank you for this post. I have same question as above. How to add a user field to a List using SharePoint Http service, if the user has never been added to the site collection users or group?

    1. Pieter Veenstra Avatar

      I don’t think that there is a way to do that unless you can add a new entry to the hidden user list uisng the api. If I remember correctly then this has been disabled

  3. Tiago Paes Avatar

    You can do a post to /_api/web/ensureuser(’emailhere/or name, if it’s AD unique’) and it’ll create the entry if it’s not on the hidden list. The result is a User object with all the properties you might need.

    1. Pieter Veenstra Avatar

      Hi Tiago,

      Thank you for your comment. That will indeed also work.

  4. TironB Avatar
    TironB

    Hi Pieter,
    just came across your great post.
    I am looking for the other way round and hope you can help.

    In my list I have a PERSON column. There 1 person is selected and stored.
    Now I want to lookup the user-id, first name, last name for each person in this list and store it in separate fields for each record.

    I tried myself but without success.

    1. Pieter Veenstra Avatar

      Hi Tiron,

      The people field is a record that contains those properties already. You can just use the json returned and then query the json.

Leave a Reply

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