In case you need to select an item from an array in Power Automate based on the value of a certain attribute, here’s how you can do it.
In the below example, we want to select the item / array of objects where we want to select based on a value of an attribute. Here, the attribute is “key” and we want to select the condition to match the value “RelatedEntities“
As you see, the array of objects have different structure – All of them have an attribute called “key” and that’s the one you want to select and then process further.
Let’s see how we do it.
Let’s see how you can select the item from the array based on the value of the “key” attribute instead of looping through all the items and matching.
- Now, let’s say the data is stored in the variable for demo purposes, that’s what I’m feeding into the Filter Array action in the Flow.
Remember what goes into the Filter Array action has to be an array data.
- In Data Operations connector, you’ll find the Filter Array action which we’ll need to pick the item with “key” = “RelatedEntities”
- In Filter Array, you set the Input to the array data which is stored in the variable shown above.
- Once you select, you then need to provide the condition to filter the Array.
In this example, we want to filter based on the “key” = “RelatedEntities” as seen in the Scenario section above.
So, in the dynamic content section, go to Expression section and then use item() function and just like you access an element in a JS, you can mention what attribute you are trying to access.
- And in the value, you can mention what the value has to be.
- And in the answer, when you run the Flow with the sample data, you’ll get the below result.
- The other elements are filtered out. If you have two items of the same value, both will be returned.
- Below is how the actual code looks like when you edit in Advanced Mode –
Hope this was useful!
Here are some Power Automate posts you want to check out –
- Blocking Attachment Extensions in Dynamics 365 CRM
- Upgrade Dataverse for Teams Environment to Dataverse Environment
- Showing Sandbox or Non Production Apps in Power App mobile app
- Create a Power Apps Per User Plan Trial | Dataverse environment
- Install On-Premise Gateway from Power Automate or Power Apps | Power Platform
- Co-presence in Power Automate | Multiple users working on a Flow
- Search Rows (preview) Action in Dataverse connector in a Flow | Power Automate
- Suppress Workflow Header Information while sending back HTTP Response in a Flow | Power Automate
- Call a Flow from Canvas Power App and get back response | Power Platform\
- FetchXML Aggregation in a Flow using CDS (Current Environment) connector | Power Automate
- Parsing Outputs of a List Rows action using Parse JSON in a Flow | Common Data Service (CE) connector
- Asynchronous HTTP Response from a Flow | Power Automate
- Validate JSON Schema for HTTP Request trigger in a Flow and send Response | Power Automate
- Converting JSON to XML and XML to JSON in a Flow | Power Automate