Filter queries in the Get items action in the SharePoint connector are quite easy, but what if you want to filter by a SharePoint People field?
The SharePoint people field setup
In SharePoint I’ve got a list that has a people field on it. This field is called Person1.
I now want to find all items in this list when a new item is added to the list that has the Person1 set to the same person as the Person1 field for the item just created.
So in short filter list items by a people field’s value found in SharePoint.
Get User ID
The flow will start with a trigger “When an item is create or modified. This will give me a user details for the Person1 field. The only thing that I will not get is the user id for the person1 user. But this is what I will need later.
A While ago I wrote a post about getting the user id for a user. In this post i’m going to use the same method again
The User It will be used later on so that I can build up the query that will look like this:
Person1Id eq 11
Person1 is my fieldname. The Id that follows this field name indicates that I query the ID of the person field. The 11 is the user id of my user.
We need to have a bit more of a detailed look at this code.
The trigger gives me the email address of the user selected in the Person1 field. Now i can query the User information List using the user’s email address.
And finally I’m getting the query completed by using the user returned in the first Get Items action. I will only ever get one user returned, therefore I can safely take just the first item in the array, avoiding on of those unnecessary apply to each steps.
The code used in this last step is: