How to break out of a for each loop inside an invoked workflow?

The invoked workflow calls break in some if conditions. The invoked workflow is invoked inside a for each loop in the parent workflow. However, this gets the error:

Activity can only be placed inside a ForEach.

What do I do? Thanks.

Pass an in/out Boolean argument from parent wf and modify the value to true in your else condition where you typically end your child wf.

In foreach after invoke activity use if condition to check if that Boolean is true or not and use break.

Sorry, what I want to do is stop running the invoked workflow, but continue the for each loop. I used terminate workflow but this stops the entire automation rather than just stopping the workflow and continuing.

Hi @roncook,

Have you tried catching WorkflowTerminatedException? Here is an example (4.1 KB)



Exactly what i needed, thanks!

Glad to hear it :-). You can achieve the same behavior using throw activity instead of terminate workflow then catching the type of exception you have used in that activity.

I agree with try catch in parent foreach loop (incase of any error in child wf).

My question is why do you want to use terminate wf activity. If you just ignore the false condition, your wf will end automatically (although it depends on your design pattern)