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


#1

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.


#2

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.


#4

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.


#5

Hi @roncook,

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

Regards,
Susana


#6

Exactly what i needed, thanks!


#7

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.


#8

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)