Today a short post, about the item function and the items function in Apply to each step.
Apply to each in Power Automate
Table of Contents
When you create apply to each step you can use the Current item to refer to the item that is being processed within the apply to each step as shown below.
Power Automate makes it easy to just select Current item from the Dynamic content and all is good! Until you looking under the hood of the Current item. We will see that the following expression is used when we select Current item:
But how about copying the action inside the Apply to each to another apply to each as we want to replicate this step. So we use the copy paste functionality in Power Automate and we might create a flow like this.
Now when we hit the save button, we will see the following error message
The template validation failed: ‘The inputs of template action ‘Compose_4’ at line ‘1 and column ‘1575’ is invalid. Action ‘Apply_to_each’ must be a parent ‘foreach’ scope of action ‘Compose_4’ to be referenced by ‘repeatItems’ or ‘items’ functions.’.
Well that is annoying, You will have to remove the current item on the right and then reselect the current item from the Dynamic content.
Item to the rescue!
Now as the expression isn’t depending on the Apply to each step anymore we can simply copy the step from one Apply to each to another apply to each and the flow will just save.
So the next time you select the Current item form Dynamic content you might want to consider using the expression editor and type item() instead.
As we have seen with copy/paste, where the items function causes some problems. If you drag and drop actions from one place to the other will give similar issues that we will not see if we use the item function instead.