Loop through list items until condition is met
Recipe Tools
What it does
When a function call arrives, this automation loops through a list and stops when a condition is met. It logs each iteration to the job report and returns the result so the caller knows what happened.
Who it's for
Engineering teams who need to process batch data with early exit logic without building custom code.
Apps used
- Recipe function by Workato
- Workato List
- Logger by Workato
How teams use this
Stop processing when threshold is reached
Loop through transaction records and break when the total amount exceeds a limit. Log each step and return the stopping point so finance can review the batch.
Find and return first matching record
Iterate through a customer list to find the first one that matches a search criteria, then exit immediately. Return that record to the calling system.
Add error handling and retry logic
Include a retry counter in the loop so failed items are attempted again before the break condition is checked. Only exit when the counter reaches its max or the condition is met.
How it works
- Receive the function call. Define the input parameters and schema for the list and the condition that will control when the loop stops.
- Repeat for each list item. Loop through each item in the list passed from the function call and evaluate it against the break condition.
- Check if condition is met. Evaluate whether the current item meets the break condition. If yes, log the result and exit the loop immediately.
- Log iteration and continue. Log the current iteration outcome to the job report, then proceed to the next item or break based on the condition.
- Return the final result. Send back the result and loop status so the caller can see how many items were processed and why the loop ended.