Filter by a SharePoint people field in Get items action in Power Automate

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

SharePoint People Field

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.

Filter by a SharePoint people field in Get items action in Power Automate Microsoft Office 365, Microsoft Power Automate, Microsoft SharePoint Online Flow run querying by user ID

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.

Filter by a SharePoint people field in Get items action in Power Automate

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:

first(body('Get_items_-_User_ID')?['value'])?['ID']
Avatar for Pieter Veenstra

By Pieter Veenstra

Business Applications Microsoft MVP working as the Head of Power Platform at Vantage 365. You can contact me using contact@sharepains.com

Leave a Reply

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

Discover more from SharePains by Microsoft MVP Pieter Veenstra

Subscribe now to keep reading and get access to the full archive.

Continue reading