Power Automate / Dataverse: Get first result

Power Automate has so many options and possibilities by clicking through the user interface. But it can do even more with the help of expressions. I think I use the following two experssion the most, empty() and first(). Thats why I wanted to share them with you.

Get the first returned value

When looking for a record in the Dataverse, but the record id is unknown we use the action List Rows. This action always returns an array of values. This even happens when only one record is returned. If you try to use the returned value to for example update the found record, then Power Automate automatically generates an apply for each loop. This can be confusing when developing the flow, why would it loop through all the values when there is just one? With the first() expression we can prevent Power Automate to automatically generates an apply for each loop.

  • Add the Dataverse action list rows and configure it to find the unique record.
  • In my example I look for the unique record based on the unique order id.
  • When trying to update the found record the following Apply for each will be automatically generated.
  • The creation of the Apply for each can be prevent by using the expression first().
  • Remove the Apply for each and the Update a row action.
  • Add a new Update a row action and open the expression tab.
  • Add the expression first(body(‘Internal_name_of_the_list_row_action’)?[‘value’])?[‘internal_field_name’].
  • This expression returns the first specified field value from the value array in the returned body of the list row action.
first(body('List_rows_-_BlackedOutName_related_with_Order_ID')?['value'])?['rc_id']

Check if the returned result is empty

In my Cloud Flow I needed to check if a List rows action did not return a value. This is not an option in the drop down list, but it can be done using the empty expression.

  • Add the condition action.
  • Open the expression tab.
  • Add the expression empty(output(‘Internal_name_of_the_list_row_action’)?[‘body/value’]).
  • This checks if the returned body have any values, with other words checks if the value is empty.
empty(outputs('List_rows_-_BlackedOutName_-_DTA')?['body/value'])