cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate V
Advocate V

Exit a flow using Terminate in a Condition action

Simple request this, but cannot find the answer in the forum.....

 

We have a form that contains a StartDate and EndDate.  As there is no way of doing client-side date validation we test the dates right at the beginning of the flow and reject the request with an email to the requester informing them of the error.  All this works fine, but when I try to use the Terminate action to halt the flow I get the familiar error message:

TerminateFlow1.PNG

 

THe requirement is: if the branch is Yes all we want to do is send the email and stop the flow.  How do we halt the flow?

 

Tks

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Dual Super User II
Dual Super User II

Re: Exit a flow using Terminate in a Condition action

OK, it wasn't clear from the original post what the loop was processing.  And that is why terminate isn't allowed inside the loop.  What we really need is the equivalent of the Break statement, which breaks out of a loop.  But that's not the same as terminate. Terminate is like Exit or End.  The problem is if allowed it would be unclear to users whether they were terminating the Loop or the Flow.  I understand for your situation its more work.



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

View solution in original post

7 REPLIES 7
Highlighted
Super User II
Super User II

Re: Exit a flow using Terminate in a Condition action

HI @MrNigel ,

 

There is no decent way to stop the "Apply to Each". There is a request  under review by Microsoft:

https://powerusers.microsoft.com/t5/Flow-Ideas/Exit-from-quot-Apply-to-Each-quot/idi-p/30760

 

There's a workaround, but I admit it's ugly. In the IF and inside the "Apply to Each", store in a variable all the emails that you want to send. After that, you need to do your "Send email to the Requestor" based on that variable.

 

I know it's inefficient letting the "Apply to Each" run until the end but, until we have a way to stop it, we need to use stuff like this.

 

Hope this helps you

 

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

Highlighted
Dual Super User II
Dual Super User II

Re: Exit a flow using Terminate in a Condition action

I don't think you actually want to do a terminate.  You are inside a ForEach loop, which means you are processing multiple requests in the Loop.  If you do a Terminate you will stop the flow and no additional requests will be evaluated.  I suspect you just want to terminate this one request.  Here's how I normally handle that

 

1) Initialize a boolean variable outside your loop that will control what your loop does.

2) Do a Set Variable as the first action inside your loop and set the variable you created to False.

3) Do a Set Variable where you were placing the terminate action and set the variable to True.

4) For the rest of the loop check that the variable is False before you do additional actions. That will keep the loop from doing anything after it finds an incorrect entry.

5) When the Loop starts on the next entry #2 will reset the control variable to False, so that entry will be processed if appropriate.

 

If you do want to shortcut the Loop then do the same thing, but omit step #2 and set the initial value to False in #1.  Then when you find an error the loop will continue, but nothing further will be processed.  Then you can test the variable when you exit the Loop and terminate if its still True.

 



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

Re: Exit a flow using Terminate in a Condition action

@PS - the issue is that I really DO want to Terminate and do nothing more.  If StartDate is greater than EndDate it is an invalid request that is rejected immediately, none of the Flow actions after the date test should be 'skipped' or run.

 

The other issue is that thanks to it being a form trigger, Flow has put the majority of the Flow in one big 'Apply to each' loop. I have already seen the variable solution posted on the forum so I went down that route, but ultimately I have to use a Condition action to test its value and that must be done outside of the main loop if I want to Terminate.

 

I have no idea what the logic is in making it so difficult to terminate a flow when a condition is met that necessitates that action.

Highlighted
Dual Super User II
Dual Super User II

Re: Exit a flow using Terminate in a Condition action

OK, it wasn't clear from the original post what the loop was processing.  And that is why terminate isn't allowed inside the loop.  What we really need is the equivalent of the Break statement, which breaks out of a loop.  But that's not the same as terminate. Terminate is like Exit or End.  The problem is if allowed it would be unclear to users whether they were terminating the Loop or the Flow.  I understand for your situation its more work.



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

View solution in original post

Highlighted
Advocate V
Advocate V

Re: Exit a flow using Terminate in a Condition action

You are 100% correct, 'Break' is EXACTLY what is required to exit a loop.  Too obscure for UserVoice......

Highlighted
Dual Super User II
Dual Super User II

Re: Exit a flow using Terminate in a Condition action

Its been requested and you can vote for it here:

 

https://powerusers.microsoft.com/t5/Flow-Ideas/Flow-loop-break/idi-p/166125



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

Re: Exit a flow using Terminate in a Condition action

So basically the Continue & Break functionalities are still not supported in Power Automate! The other options of Do While and conditional boolean variable usage are just workarounds. 

Helpful resources

Announcements
firstImage

Super User Program Update

Three Super User rank tiers have been launched!

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

Join the new Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Top Solution Authors
Users online (4,915)