Power Automate Step-by-Step Instructions for the D365 Admin – Day 3 Blog

Day 3 Post: Apply to Each

Now that we have The Setup completed for a Power Automate Flow, it’s time to set up the first flow action. If you haven’t gone through Day 1: The Set up or Day 2: List Action Records please take a moment to go through them first.

As a reminder, our scenario is to complete the following:

The Scenario

Let’s assume we want to run an advanced find query against a Dynamics 365 custom entity, loop through the result set, and create a task when we find a data anomaly in our system. For example, perhaps contacts can only be linked to Active Accounts, so let’s find all contacts linked to inactive accounts.   We can then create a task for somebody to investigate each Contact linked to an Inactive account.

To build on Day 2:

(20) Now, add an “Apply to each” action – this will let you loop through the records returned by the List Records action, and perform an action on each.  Search for “Apply”, and select the control action.

Power Automate for Microsoft Dynamics 365 step-by-step instructions for the System Administrator

Your Power Automate design panel will now look this like:

(21) Feed the data from the List records query into the “Apply to each” block.  To do so, click into the “select an output” box.  The “Dynamic Content” box will open.

Confusion Point #2:

If you don’t see the image above, you may be using a device that doesn’t have enough space to display this dynamic fields box.  Increase your resolution until you can see it.  (I always develop flows on a big monitor, for this and other reasons.)

(22) Click on the “value” line from the dynamic menu.  Your designer screen will look like this:

Confusion Point #3

Now, in addition to the “New Step” button, you now have an “Add an action” button.  They do exactly the same thing, bring up the action window.  The difference is that the “Add an action” inside the “Apply to each” block will cause that action to happen for EACH record in our result set.  The “New Step” button will create actions that happen OUTSIDE of the Apply to each block, in other words, only once.  (Typically you might do something like log the flow action was completed, or send an email, etc.)

Using Components from the List records action

Now that we have entered this “value” placeholder into the “Apply to each” block, we can refer to the field returned by the List records action, in other actions.  In our scenario, we want to create a task to investigate active contacts linked to inactive accounts.  In that task, we can add things about the Contact record we are processing.