top of page
Writer's pictureMatthias Schmitz

How to get one record using first() instead of using Apply to each in Power Automate

Updated: Feb 21

I would like to cover one of my best practices in today's blog post for working with Power Automate.


You probably encountered during your work with Power Automate that for example the Dataverse List rows action will give you automatically an Apply to each loop action. Which is totally fine if you want to process several rows of data.


However, there might also be the case that you are looking for one specific record and you don't have the GUID but you get the number or the name of the record from another step. In this case you will probably apply the Filter rows or Fetch XML query property of the List rows connector.


If you don't know how to do this, you can check my other blog posts about this:


If you apply those filter correctly, you will get your single record that you want to see. However, if you now use it in your Power Automate flow you will get an unnecessary Apply to each action.


As shown here in the compose action to get the Account Name of the account with the Account Number 123:


This might look harmless at first and it is if you don't use further actions. Imagine you will use more actions inside this new loop. Maybe a real Apply to each action. In this case you would have Apply to each within Apply to each.


Now you can imagine already that it might get too complicated for other people to read and understand your flow. And also further reasons, maybe even the performance might be worse.


Luckily, there is a solution for this. Use first() on the body you get as the output of the List rows action.

As shown in this compose action:


By using this way we can get all the data of the record. You just need to change the last piece from 'name' to the technical name of whatever field you want to see:


first(outputs('Get_specific_account')?['body/value'])['name']


 

Conclusion

The usage of this little function first() will make your flows way more readable and enjoyable. Not only for you when you come back months later to check on this flow but also for other developers. Nevertheless, don't forget to make the name of your action steps as readable as possible ;)




168 views0 comments

Comments


bottom of page