cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Exit ForEach loop with condition (like in a WHILE statement)

filipe-oliveira
Deputy Chef I
Deputy Chef I

Hello Workato Community,


Is there a way to exit a ForEach loop given a specifc condition (like in a WHILE statement)?


I'm just looking for an ID in a list and I want to stop the ForEach once the ID is found.

I added an IF condition inside the ForEach but, as per my understanding, this would just prevent the following steps inside the ForEach from being executed, but the ForEach would still need to iterate through the whole list.




Thank you,

Filipe

9 REPLIES 9

david-macintosh
Deputy Chef I
Deputy Chef I

You should looking into droppong your list into a collection then execute SQL against the collection to get your desired entry / entries. I have found this extremely useful for limiting iteration as well as nested looping, greatly reducing the complexity and size (number of actions) required for various recipes.

omri-benmoshe
Workato employee
Workato employee

Hello Folks,

You can use this pattern to break form a loop.

Loop Break Example


omri-benmoshe
Workato employee
Workato employee

I've added a link to EU Costomers

Loop Break Example EU

kolson
Deputy Chef I
Deputy Chef I

Hi Omri - doesn't the Stop Job exit the entire job? What if you want to continue processing after you leave the loop?

brock-richard
Deputy Chef I
Deputy Chef I

Hey Kris, because the error that is being thrown is inside of the Monitor block, it just exits the loop, and the following steps after the On Error block will continue to be executed.