For an unknown reason, probably a good one, you can’t add a Terminate Action inside an Apply to each Action/block. Instead, you get an error such as:

The operation ‘terminate’ cannot be used inside a for each.

A workaround to this is to use a Do until Action instead, but that can quickly become more complicated when you have to manage your own iterator, which Apply to each does for free.

Solution

Instead, you could use a variable to track success of all Actions within the Apply to each Action and have a condition below the Apply to each which can be used to branch into an unsuccessful state.

Initialize a new boolean variable, eg. IsCompleteAndSuccessful, but set its default position to true. Therefore, all operations within the Apply to each are assumed to be complete and successful unless proven otherwise.

We can prove otherwise by setting the same variable to false

… ensuring we only run that Set variable Action if the Flow fails:

The downside of this approach is that the loop must exhaust itself before we can react to the failure. However, adding a Condition Action to react to this variable after the Apply to each Action is trivial:

This allows is to react and respond with a Terminate Action, allowing a parent Flow to react and only executing dependent Actions/Flows if appropriate. Using the Terminate Action also allows parent Flows that are calling this Flow to terminate quicker if they have an error handler configured to fire if there was a Timeout.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Quote of the era

In the beginning there was Jack … and Jack had a groove. And from this groove came the groove of all grooves. And while one day viciously throwing down on his box, Jack boldly declared “Let There Be House” and House music was born.

~ Chuck Roberts