I need to break out of a loop within a invoke workflow

In this for each loop I have a few invoke workflows based on how the data is read. I pass arguments into a workflow called date verification. When the bot is finished running it goes back to another for each loop inside not to the first one. I have read that using a try catch is the way to go with this issue but I am unclear as to how to integrate this entire process and where to put all of this. Here is the if statement at the end of the process.

Hello @jeff.shubzda ,

Have you tried to break the inside loop using Break activity ? If yes, what is the outcome ?


Yes the bot works well when I have a break in the first for each however if it runs down into another workflow in the else statement I can’t use a break I get an error.

This break works but if the bot enters that other workflow it ends and comes back to this for each not the outside one.


Can you try to use Try Catch for the invoked workflow and instead of using break, throw an exception. Try catch will catch the exception and exit out of the workflow.


Hi @jeff.shubzda ,

Maybe we can use a Boolean Argument (out) inside the Workflow, such that whenever it is the Break Decision, assign the Boolean Argument to True and then Break, Check this Boolean argument value Outside the Workflow, If True then Break again.

This way we will be able to Break from the Outer For Each Loop as well.

Let us know if it doesn’t work

I tried to use the try catch and it still went back to the inside for each. Just so you know this is my 2nd bot and it’s been very complicated for me. It’s very difficult to describe what is happening here and I haven’t used Boolean arguments yet so I’m clueless as to where to begin this process. Sorry I haven’t done a ton of this kind of work.

@jeff.shubzda , Is it possible for you to provide the Workflow ?

Probably not due to sensitive material of healthcare. Sorry. I appreciate the help. Like I said it’s a compilated process and this bug is what is holding up the testing of the bot due to the fact it can’t get out of the inside loop.

The workflow moves from for Each workflow into invoke workflow of address verification to number workflow to date verification work flow. Once it hits the end of the date work flow what happens is that the process returns to the for each loop inside of the address workflow when it really needs to go to the foreach loop in the forEachDateRows workflow.

Okay, understood. So what if you give a break statement just after where you are invoking the “Address” workflow? Is that giving you any error?

I tried a bunch of scenarios of breaks and continues in this workflow with different results. Not the one I need though. I can see it in the logs as the bot comes back and grabs the next address in the row but it needs to grab the NPI number first before grabbing the next address in the row that tells me it always goes back to the for each loop inside of the workflow, not the outside for each. thanks

@jeff.shubzda Please try to use stepinto feature in the Debug panel. Also enable the Highlight Elements feature. Then StepInto each activity and see how the flow is happening overriding the break.


I stepped into the process and oddly the process goes all the way back to a sequence right before the for each and begins the process again telling me that it just misses the for each loop. It really doesn’t make any sense, I have a break at the end of the invoke workflow which should break me out of the loop.

Hi Jeff,

As per my understanding, the execution is not going inside the Invoke Workflow activity and directly going to the previous steps. Plz, correct me if my understanding is wrong.

If this is the case can you check whether the arguments are properly imported in the invoke workflow activity? Also, you can try invoking a very simple workflow with a message box instead of the current workflow to debug where the issue is happening.

Correct it ends here

In the Try Catch, the else statement on the left breaks to the next row in the data table but for some reason the then statement runs the PIN and Date verification workflows and needs to breakout and start again at the parent for each loop. See pic it needs to get back to the workflow of the ForEachDataRow (row = dt_verity) it seems to only make it the sequence below.

I think here in the left Try catch, the flow is moving to Catch due to some error and then executing the Finaly(Break condition)… As you mentioned its not moving inside the Dataverification.xaml workflow. Please Validate the workflow once. Also, try to print the exception getting caught in the Catch. It will help to debug

Sorry it does move into the date verification area, sorry my bad and runs that verification but when it comes out of that workflow it can’t get back to the for each (row in dt_verity) it gets back to the sequence below it that i have an arrow drawn

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.