I want to exit from "Apply to Each" for exit the loop.
In some case, the loop does not need processing items after specific item.
Thank you for suggesting this idea, it is a good suggestion!
Does any have solution to this ? I have similar case where i need o exit out of loop or terminate the Flow instance if condition 4 is "No" .Note - Apply to each is set to run in parallel for parallel approvals.
Please provide an exit to apply to each. Would be great to terminate if criteria isn't met and prevent the rest of the logic app from processing. Thank you!
I have a payload URL checking for updates on any item added to a specific group within an ArcGIS Enterprise Portal with around 70000 users. If this idea is not implemented it creates so many failure emails for items that do not satisfy the condition. Please promote this functionality into the product. Kind of absurd to not have a break statement for an apply to each function (loop).
No need to spam ArcGIS users with unwanted emails. Use an IF... 🙂 If you need it done fast you can pass the paylosd through an Azure app function that forwards the payload to Power Automate.
Otherwise try filtering the array as per my link above.
I would like to share my workaround. This can be done by using "Do until" loop instead of "Apply to each" and variable as a counter. Look at my example to find a user.
First initialize the counter variable.
Then use the "Compose" to get number of items, in my case group members.
Create "Do until" loop and set to check if counter variable is equal to number of items.
In "Condition" you have to use expression to get the item for iteration corresponding to the counter variable value. In my case to get Display Name and User Principal Name.
Then add to "If no" increasing a counter variable by 1.
Inside the "If yes" add your own function and set the counter variable to number of your items declared earlier. This will terminate the loop after finding the item you are looking for.
As you can see it works. Look at the comparison. The user found is 21 out of 75 so "Do until" loop finished 21 iterations when "Apply to each" loop has done all 75 iterations. Time for "Do until" is 9s and for "Apply to each" is 21s.
At the end, don't forget to change the limit because default is 60 counts.
Break/Continue style commands are keywords in many, many programming languages, because they're fundamental parts of loop control.
Using 'Until' rather than a "Foreach" is incredibly clumsy, especially when the environment itself is clumsy.
Please focus on the basics, before you go running off on whatever the 100 other things you think are more important.
We'd like to create flows that are maintainable long term - that means having simple language constructs!
@TristanJamesBal - You nailed it.
@TristanJamesBal yes, you're right using until rather than a foreach is clumsy. When I realized there's no break in the foreach loop, I was so shocked. This is the basis of any programming language but Microsoft hasn't implemented this solution for about 3 years so the only what I can do for now is workaround or say goodbye to Power Automate.
It's a pity this feature doesn't exist.
It's particularly annoying because I'm getting a message that my flow will be turned off because it's using too many actions.
If I could break the loop when a condition was met, I'd probably only need 2-3% the number of actions 😑
Let's get this Exit Loop option installed already! How many votes do you need to get this done? Over 200 seems like enough for this community of developers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.