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

Terminate Flow inside For Each Control

My trigger is from Forms for an approval process. 

 

But before I move forward for Approval process i want to exclude some responses on a criteria based on the form. I did that but i was not able to terminate the flow after that. As Terminate control does not work in for-each condition. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Hi @sjehanzeb ,

 

Terminate action cannot be used inside a for each loop.

 

Please try if the following workaround will work for you.

 

Please initialize variables in your flow, outside of the Apply to each loop, add Condition or other actions, then terminate the flow under If yes or If no branch.

1.PNG

 

Best regards,

Mabel

 

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Highlighted
Dual Super User III
Dual Super User III

@sjehanzeb 

I also miss this feature, you can vote its implementation here: https://powerusers.microsoft.com/t5/Flow-Ideas/Flow-loop-break/idi-p/166125

Is your loop a do-until? If so, as a potential workaround, have you taken into account the following possibility?

Step#1: DEclare an auxiliary boolean variable 'Stop Loop' with default value to false before the for each control

Step#2: include the evaluation of this new variable in your do-until condition

Step#3: inside your do-until logic, turn to 'Stop Loop' to true whenever you want to stop new iterations

Step#4: just after the do-until, add a condition to evaluate 'Stop Loop'. In the 'true' branch, add a Terminate action block.

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Highlighted

I am inside the 2nd "For Each" loop. Will it work if i encapsulate the entire flow in "do-until" with a boolean check 

 

Highlighted

@sjehanzeb 

Can you share a screenshot with your flow details, so we can get more info on what you are working on, and see if the suggested workaround can be applied on your use case?



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Highlighted
Community Support
Community Support

Hi @sjehanzeb ,

 

Terminate action cannot be used inside a for each loop.

 

Please try if the following workaround will work for you.

 

Please initialize variables in your flow, outside of the Apply to each loop, add Condition or other actions, then terminate the flow under If yes or If no branch.

1.PNG

 

Best regards,

Mabel

 

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted
Regular Visitor

This solution also works when you are forced to place an Approval action inside a For Each! If you set the outcome as a variable, you can then use that variable as described above to terminate a rejection. Otherwise, a rejection inside of a For Each will NOT terminate a Flow.

 

If you are curious as to why I have to place an Approval inside a For Each, I am performing a SQL stored procedure to validate a new form value against a database for existence that creates a dynamic message for the approver inside the Flow message. With the limitations of Flow and SQL connector gateways, I could not find any other way to generate my validation.Approval For Each Termination.jpg

 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Top Solution Authors
Top Kudoed Authors
Users online (6,676)