Search code examples
power-automateworkflow-definition-language

MS Flow: How to achieve something like `_.find()` (lodash/JS)


How can I use MS Flow to select an individual object, by value for a specified property, from an array?

Example array:

[
  {
    item_id: '1234'
  },
  {
    item_id: '4567'
  }
]

In the example above, I may only want to work with the first object and the rest of its available properties.

Happy to use the Workflow Definition Language and/or any of the Data Operations actions.


Solution

  • I solved this by using the "Data operations - Filter" action. enter image description here

    Ignore the error in red - it is an array.

    My left-hand expression for "item_id" is:

    item()?['item_id']
    

    And then I statically enter the item ID I wish to access in the right-hand input.

    DocumentNo Item will then be an array itself with only 0 or 1 elements and can be used like so:

    body('DocumentNo_Item')?[0]?['label']