Stop Power Automate flow from adding ‘Apply to each’ automatically
Posted On November 21, 2021
“Sometimes, when I use specific dynamic content, Power Automate adds the ‘Apply to each’ action automatically, how can I stop it? I don’t want to repeat any of the actions!”
You surely encountered this when building a Power Automate flow. You add the actions you need and use the available dynamic contents to configure them. It goes fine, until you add that one dynamic content. Once you add it, it’ll add ‘Apply to each’ around the action. And that’s where the problems can start. The flow will send multiple emails instead of one. It’ll create duplicate SP items instead of one item with multiple values. Or it could just stop working completely. Why does Power Automate do it and what can you do about it?
Why is it adding ‘Apply to each’?
Power Automate adds ‘Apply to each’ automatically every time you’re trying to access value from an array. As explained in the post on processing JSON, you can recognise arrays by the brackets [ and ]. Anytime you try to access anything inside [ ], Power Automate will automatically add ‘Apply to each’. It recognises it’s an array, and as such it wants to process all the objects/values. One by one, inside a loop.
That means, to avoid the ‘Apply the each’ you must extract the object/value from the array differently. You can’t leave it up to Power Automate.
Get rid of the array
You must extract the values from the array and turn them into a string, or select only a specific object/value from the array. There’re multiple options how to do it, depending on the array and how you want to use it.
Power Automate will add ‘Apply to each’ each time you try to process an array and the only way to stop it is to preprocess the array by yourself. The actual processing depends on what you’re trying to achieve. If you want a specific value(s), you can use one of the first 3 options. If you want the whole object for later processing, the last options is what you’re looking for.
Just don’t forget to remove the automatically added ‘Apply to each’ at the end. Otherwise it’ll keep looping even after you preprocess it.