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.
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.
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.
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']
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
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.
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?
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
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.
Hi Tiago,
Thank you for your comment. That will indeed also work.
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.
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.