cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
tissanfr
Frequent Visitor

How to stop a "apply to each" ?

We have a "apply to each" loop that we want to stop when a certain condition is found. 
But we can't find any way to stop it. "terminate" isn't working in an "apply to each"

 

I see that there is a "Do until", but it can find how to put the stop condition. 


Basically, our job is like that :

 

Apply to each
Test 1, if true, write the record and stop
           if not true, then Test 2, if true, write the record and stop

                                     if not true, keep going


If it possible to write both tests in the "do until" condition ? Thanks !

1 ACCEPTED SOLUTION

Accepted Solutions
abm
Super User
Super User

Hi @tissanfr 

 

'Terminate' flow action can't be used under For Each Loop.

 

If you planning to use Do Until you need to make sure that condition should meet until it satisfies. If not you could end up on infinite loop.

 

Why not filter the condition for true first do the update. Next filter the dataset for false and do the rest. This way you still use the for each loop. The only issue is you have two for each loop. One for true condition to do the job and next for the false.

 

Hope it make sense. 

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blogPower Automate Video Tutorials

View solution in original post

5 REPLIES 5
manuelstgomes
Super User
Super User

Hi @tissanfr 

 

"For each" will always run until the end for all items.

If you want to keep a certain value I recommend having a variable in the "For Each" that keeps the value that you want or filter the array that is sent to the "For Each" so that less values are parsed.

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Cheers
Manuel

Pstork1
Dual Super User III
Dual Super User III

Its a little extra work, but you can use a DoUntil Loop to do your processing.  

1) Initialize a Boolean variable to False to control the Loop

2) Set your DoUntil Loop to run until the Boolean you created is True

3) Use the CurrentIteration value as an Index to the JSON value of the collection you want to process

4) When you find your finish condition set the variable to True.

 

The Tricky part is #3.  If I'm processing the rows in an Excel table then this would be the JSON formula

body('List_rows_present_in_a_table')?['value'][iterationIndexes('Do_until')]

 This accesses a row from the list rows present in a table action based on the current iteration of the loop.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
abm
Super User
Super User

Hi @tissanfr 

 

'Terminate' flow action can't be used under For Each Loop.

 

If you planning to use Do Until you need to make sure that condition should meet until it satisfies. If not you could end up on infinite loop.

 

Why not filter the condition for true first do the update. Next filter the dataset for false and do the rest. This way you still use the for each loop. The only issue is you have two for each loop. One for true condition to do the job and next for the false.

 

Hope it make sense. 

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blogPower Automate Video Tutorials

View solution in original post

Anish_PBIGuy
New Member

I have a similar query. I am using power bi to send reminder emails to the end user basis on the aging bucket which I have created. However, when I run the flow it is sending multiple emails to single user. I need help with only one consolidated email with all the again bucket details within per user. 

 

 

 

Hi @Anish_PBIGuy 

 

Could you please create a new thread for this? 

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blogPower Automate Video Tutorials

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (3,336)