Summary
This article explains the Get Items action in detail, and provides several tips and tricks for filtering data from SharePoint to make Power Automate flows faster by reducing the amount of data being retrieved and leveraging SharePoint's index.
Body
Summary
The Get Items action in Power Automate can be used for retrieving specific items from a SharePoint list. The Filter Query can be used for choosing which items to retrieve, but both the OData protocol and SharePoint Online lists have peculiarities that must be carefully considered. This article explains the Get Items action in detail, and provides several tips and tricks for filtering data from SharePoint to make Power Automate flows faster by reducing the amount of data being retrieved and leveraging SharePoint's index.
Steps
Project setup and SharePoint list details
- In this example, we are using a custom list called People, which is part of the TrackMaster project, and contains the following columns:
- Full Name (renamed from Title) - single line of text
- Teams Account - single-value Person or Group
- Group membership - multi-value (multi-select) lookup, pointing to "Groups List" list which contains a Title, ID and other details. A user can be part of multiple groups.
- Active - yes/no (checkbox)
- Contact Type - single-value choice (drop down)
- Primary Team Engagement - single-value lookup, pointing to "Teams List" list which contains a Title, ID and other details
Relevant columns from People list in TrackMaster
Column (Display Name)
|
Type
|
Internal Name
|
Full Name
|
Single line of text
|
Title
|
Teams Account
|
Person or Group
|
TeamsAccount
|
UniqName
|
Single line of text
|
UniqName
|
Research Areas
|
Managed Metadata
|
Publication_x0020_Topics
|
Contact Type
|
Choice
|
ContactType
|
Group Membership
|
Lookup
|
Group_x0020_Membership
|
Active
|
Yes/No
|
Active |
- Using a Power Automate flow with just a manual trigger, add a Get Items action.
Overview of Get Items action
- Site Address - the URL of the SharePoint site. (In TrackMaster, where all Power Automate flows are part of a Solution/Project, we use an environment variable to set the site URL so that the solution can be deployed to different departments on their own SharePoint sites).
- List Name - the SharePoint list from which to get data.
- Limit Entries to Folder - Both document libraries and lists can use folders for organization. In the case of lists, "Enable Add Folder" must be checked in the list settings in order to use folders that will show in this field.
- Include Nested Items - If using folders, Yes/No indicating whether to retrieve items in sub-folders or not.
- Filter Query - An OData filter query that narrow down which items will be retrieved. This field is the primary focus of this article.
- Order By - An OData sort query (optional).
- Top Count - Limit how many items to retrieve. If combined with Order By, this can be used to bring the latest or oldest items only.
- Limit Columns by View - A performance optimization option that will limit the columns retrieved to those set in a specific view. In TrackMaster, we normally create Power Automate-specific views that only contain the columns that are absolutely needed by all the flows accessing a particular list. This cuts down on the amount of JSON/XML data that Power Automate needs to retrieve from SharePoint and process inside the flow.
Overview of Filter Query option
- The Filter Query field in Get Items actions allows filtering for specific items in a list. The filter must be specified as OData query within the limits of the SharePoint REST API.
- General operator format:
<Internal Column Name> <comparison operator> <value> <logical joins> ...
- Comparison operators:
- lt - less than
- le - less than or equal to
- gt - greater than
- ge - greater than or equal to
- eq - equal to (numeric or string)
- ne - not equal to (numeric or string)
- Note that all these operators are lowercase
- Functions:
- startswith( column_name , 'string_to_check' ). Note that startswith is lowercase, the string value must be surrounded by single quotes, and the column name is provided before the string
- substringof( 'string_to_check' , column_name ). Note that substringof is lowercase, the string value must be surrounded by single quotes, and the column name is provided after the string
- day()
- month()
- year()
- hour()
- minute()
- second()
- Special functions: some Power Automate functions can be evaluated when placed inside single quotes, such as 'utcNow()' to get the current date
- Logical operators:
- and
- or
- not( )
- Note that all are lowercase
- Special fields and property access:
- TaxCatchAll - virtual column used for searching Managed Terms in any column in the list, via TaxCatchAll/Term or TaxCatchAll/IdForTerm
- To access lookup fields, use ColumnName/Id for the numeric ID and ColumnName/Title for the display name. For example, the 'Group Membership' column can be filtered for the group MDEN, which has an ID=5, as either: Group_x0020_Membership/Id eq 5 or Group_x0020_Membership/Title eq 'MDEN'
- Similarly, to access properties of a Person or Group column, use:
- ColumnName/Title for the person's or group's name
- ColumnName/EMail for the email address (note that E and M are uppercase)
- ColumnName/Department for the department name
- ColumnName/JobTitle for the job title
- Special columns and rules:
- Title - all lists are required to have a Title column, which remains the same even if the display name is renamed
- _x0020_ - not really a column, but it should mentioned that OData uses internal SharePoint column names.
- Normally, this means that if a column was created with a space in it, the space will be translated to its hexadecimal ASCII equivalent.
- For example, 'Group Membership' would have an internal name of 'Group_x0020_Membership'.
- The internal names can be found by exporting the output of the Get Items action after retrieving an item, or by looking at the URL of the column settings page under list settings in SharePoint.
- If a column is renamed, only the display name changes (the name shown in the UI) but the internal name remains the same. For example, in Track Master, we initially called a column 'Publication Topics' but then renamed it to 'Research Areas.' The internal name still remains 'Publication_x0020_Topics'
- Yes/No columns return true/false, but to filter in OData, use 1 for true/yes and 0 for false/no.
- Optimization Tips:
- Use parenthesis ( ) to group operators logically. E.g.: Title eq 'Gabriel Mongefranco' and UniqName eq 'mongefrg'
- Narrow down the results as much as possible with OData filters before bringing them into Power Automate. This leverages SharePoint's indexing engine, reduces network traffic, and reduces the amount of data that Power Automate will need to process and/or loop through, helping flows run faster
- If after narrowing down the results you still expect large amounts of data, use XPath functions and/or Filter actions to filter the data further. Avoid loops whenever possible.
- Be careful of using /Id and /Title to access multi-valued lookup columns, as they results may vary depending on the status of the column indexes, particularly when a list exceeds 5,000 items. Instead, consider this alternative approach using XPath: How to check if a SharePoint multi-select lookup column contains a specific value in Power Automate
Examples
- Filter a simple Text column
- Look for values where UniqName = mongefrg OR mongefrg2
(UniqName eq 'mongefrg') or (UniqName eq 'mongefrg2')
- Filter a Yes/No column
- Look for Active users only
Active eq 1
- Filter a Managed Metadata / Terms column
- It is not possible to filter managed metadata columns (a.k.a., managed terms, enterprise keywords, or tags) in the Get Items action. However, you can filter for the existence of a specific keyword in any column by using TaxCatchAll (taxonomy catch all virtual column).
- Look for users with research areas of 'Other'
(TaxCatchAll/Term eq 'Other')
- Another approach is to use an Xml View Query, which requires sending an HTTP request to SharePoint. This approach is more complex and may involve security risks.
- Filter a single-value or multi-value Lookup columns
- Look for users who are part of the MCN (ID=4) or MDEN (ID=5) groups
(Group_x0020_Membership/Id eq 4) or (Group_x0020_Membership/Title eq 'MDEN')
- See limitations under Optimization Tips. Consider this alternative approach using XPath: How to check if a SharePoint multi-select lookup column contains a specific value in Power Automate
- Look for users whose primary Team is Mobile Technologies Core
(PrimaryTeamEngagement/Title eq 'Mobile Technologies Core')
- Filter People or Group columns
- Look for users with a specific email address or whose full name begins with a specific text. (Note: at Michigan Medicine, names are stored as Last, First instead of First, Last)
(TeamsAccount/EMail eq 'mongexxx@xxx.xxx.edu') or (startswith(TeamsAccount/Title, 'Mongefranco'))
- Filter for People columns (Office 365 user accounts) with specific departments or job titles
(TeamsAccount/Department eq 'MM Eisenberg Family Depression') and (TeamsAccount/JobTitle eq 'Data Architect')
- Filter single-value choice columns
- Find contacts whose contact type is staff, which is a dropdown value
(ContactType eq 'Center Faculty and Staff')
Notes
Resources
About the Author
|
Gabriel Mongefranco is a Mobile Data Architect at the University of Michigan Eisenberg Family Depression Center. Gabriel has over a decade of experience in data analytics, dashboard design, automation, back end software development, database design, middleware and API architecture, and technical writing.
| |
|