When you add dynamic content to actions you will get those unwanted apply to each actions added by Power Automate.
Wanted Apply to Each
How do you avoid these unwanted apply to each actions?
Before anything else I’m first going to have a look at the apply to each steps that are added. They are definitely not all unwanted!
Just imagine that you collect a number of files from a document library in SharePoint and then you want to process them.
So you’ve got you get files action and then you add a compose action or any other set of actions that you might want.
Then you decide to use some dynamic content from the Get files action and the Apply to each step is added by Power Automate.
So far so good and there isn’t really a problem with this Apply to each action at all. Power Automate was actually being very helpful!
Unwanted Apply to Each
Now, I will look at the unwanted Apply to each in Power Automate.
In my case I’m going to query a list in SharePoint that has a multi select field called Favourite Ice Cream using the Get item action. Another common field type that will show this same issue is with multi select people fields.
As I add dynamic content to my compose I will get an Apply to each step added again, but actually all I wanted is get the property Favourite Ice Cream out of my list item.
I don’t want this Apply to each step in this case. In one of my posts earlier this week about comparing content in Lists and Libraries, I would bump into the same issue with the select actions if I was to compare the documents based on a multi select field.
Another use case for example is when you have multiple people in an assigned to field and you want to send out a single email to multiple people.
You wouldn’t want an Apply to each that makes you send out separate emails to everybody. Assuming that you want to send out a single email to all people mentioned in a people field..
Avoiding the unwanted Apply to Each
So now the big question to answer, how do we avoid those unwanted Apply to each steps?
We will first need to look at the code behind the Apply to each and the Compose action inside the Apply to each.
The Apply to each takes the Favourite ice cream field. This array of values will then be processed inside the apply to each
Now looking at the compose action we will see the items function getting the value of each individual item.
Putting these two expressions together we will get the following expression
If you need an explanation about this querying json then please have a look at my query json post.
When the above expression is used, the apply to each will not appear and I can do whatever I like with the data.
Quite often I’m running into these issues with the select action or send an email action, but really these Apply to each actions could appear with any action.
Note that you cannot use dynamic content to get this expression into your actions, you will have to either type the expression in the expression editor or like I did create an unwanted apply to each step first and then copy the expressions created into an editor and merge the bits that you need.
Personally I use notepad as it is plain and simple but any editor will do.