cancel
Showing results for 
Search instead for 
Did you mean: 

Escape from Repeat Based on condition

prp_proton
Deputy Chef II
Deputy Chef II

How to escape from a repeat loop in workato when a specific condition is met? Repeating entire list and check condition is bad for the performance.

I don t want to  use monitor functionality and throw error to escape from the loop.

is there any alternate solution present?

4 ACCEPTED SOLUTIONS

gary1
Executive Chef III
Executive Chef III

If you're calling SF within the loop and you need the SF response/flag to break the loop, then the simplest way to accomplish this is to use the error monitor. It does exactly what you need and will not process the full list once the loop is broken. You can configure it so it does additional processing after the catch/break.

Is there a reason don't you want to use the error monitor? 

View solution in original post

javier-riesco
Workato employee
Workato employee

Another possible workaround to this is to utilize a Recipe Function. Within the Recipe function, include the necessary loop and condition. Once the condition is met, use the Return function to exit the Recipe Function and return to the parent recipe.

View solution in original post

mppowe
Executive Chef I
Executive Chef I

Yea I agree about the Monitor/Error block.  I resisted using it at first b/c it felt un-intuitive and a bit of an eyesore for this purpose, but I embraced it b/c it's easy.  The recipe function idea is a good one too, but you may want to save the task usage if you'll be calling this recipe (and/or the function) many times.

View solution in original post

marlon-muela
Workato employee
Workato employee

Hi @prp_proton ,

It depends on your use case; for example, if you want to stop the loop after several lists or indexes, you can add a condition and a monitor action to move to the next step in the recipe. Here's an example:

marlonmuela_0-1695377061052.png

 

View solution in original post

17 REPLIES 17

@gary1  is right, I have recipes that catch errors but don't fail out.  They handle the error then move on.  In those cases the Job History doesn't show failure.  The "Error Message" from the Catch block is populated, but that won't show anywhere unless you're exposing that in the Job History

@mppowe, @gary1 : I mean to say, if we are monitoring the repeat step using try catch and based on the condition, want to get out of the loop, so when ever the condition match, the action will be marked as error to go to the catch block. I agree that in Catch block we can mark it as successful, but in the job history will is not show the  action as RED MARK. is this appropriate to implement like this?

Also, if any real error happens inside the repeat (i.e connectivity issue to another system) that will also endup to the same catch block.

It will not show as a red mark unless the job fails. 
When I throw the error to exit the loop, I use a specific error message. Then in the catch block, check for that message. D it matches, you move on, otherwise handle the unexpected error like normal. That way if you want to to fail it will. 

sampath
Deputy Chef III
Deputy Chef III

I usually write python or ruby module for that purpose.

So, do I need to do the entire loop processing inside the ruby module or in ruby, there is an option to exit from the workato provide repeat action?