May 15, 2020

Power Automate - Loop through a list of records

Unarguably, It is necessary to learn how to use Power Automate/ Flow instead of Workflows. To be honest, I am sceptical on replacing all the complex workflows we have been developing for many years. In my mind, I try to figure out different approaches to address different requirements. This is the first post from a series I am planning to illustrate what I found. This shows how to loop through a list of records and perform the same action for each.

In my example, I have only three steps as shown below.


I am triggering for any update happen for Account record. This is simple.


Here I am reading a set of records from an entity called Office using a control called List Records (which I rename as OfficeList). One Account can have multiple Offices. Office entity have a lookup field called Main Account (su_mainaccount). Here you can notice how Account Id from triggering step being passed to map with Main Account, so related Office records would be returned.


Now I am using Apply to each control and most importantly I am passing List of records (type of Office) returned from  previous action.


Now, inside the Apply to each control I am creating a Task. In fact, we create task for each record in the list.


Here is one such task being created. Circled text shows the Name of the Office record, where I have passed as a variable in above control. So each office will get their respective names in it.


Hope this helps.