Repeat for each item or run steps side by side
Process each invoice in a list one at a time, or run independent steps at the same time, using the loop and parallel steps in a workflow.
Use a loop when the same steps should happen for each item in a list, such as each overdue invoice. Use a parallel step when several separate jobs can happen at the same time, such as updating your ledger and your CRM.
Before you start
Have an earlier step that returns the list to process. For parallel work, choose jobs that do not need each other's results.
Repeat for each item
- StepFind overdue invoicesA list of invoices comes back.
- StepLoop: for each invoiceThe steps inside run once per invoice.
- OutputReminder sentOne email per invoice in the list.
Add the Loop block
Drag Loop from Core Blocks onto the canvas. It appears as a box.
Choose what to repeat over
Choose the box. Leave Loop Type on For Each — iterate over a collection. Under Collection, point at the list from an earlier step, such as the invoices found. See Use results from earlier steps.
Put the steps inside
Drag the steps that should happen for each item into the box, where it says "Drop blocks here to add steps". Inside the box, a step can use the current item, such as this invoice's customer and amount.
Join what comes after
Join the box to the step that should run once every item is done.
Good to know about loops
- Items are worked through one at a time, in list order.
- If a step fails for one item, the loop stops there by default. Open the run under Runs to see the failed step.
- Stop When ends the loop early once a check is true, such as when a running total passes a limit.
- Batch Size works through the list in groups of that many items.
- A loop runs its steps once per item, unless it stops early or an item fails. The editor also lists For — repeat N times and While — repeat until condition is false, with Iterations, While Condition and Max Iterations, but these are not used when the workflow runs. Use For Each.
Do several things at once
- TriggerDeal closes
- StepParallelTwo branches start together.
- StepCreate the customer in QuickBooksBranch one.
- StepPost to #finance in SlackBranch two.
- OutputBoth doneThe branches join before the workflow continues.
Add the Parallel block
Drag Parallel from Core Blocks onto the canvas. It appears as a box.
Add the branches
Drop the steps for each separate job into the box, where it says "Drop blocks here to add branches". Each branch runs on its own.
Choose what happens if a branch fails
Under Strategy, choose Wait All — wait for every branch or Fail Fast — stop on first error.
Use parallel only for jobs that do not depend on each other. If one step needs another's result, such as the new customer's ID, put them one after the other instead.
Check it worked
Test with a short list. Under Runs, check which items were processed and what each branch produced. A reminder inside an invoice loop sends once per invoice, not once per customer.
If something goes wrong
If the loop does no work, check the list it receives. If an item or branch fails, read the step error before retrying: earlier writes may have completed. See Fix and retry a failed run.
Related
Make a decision
Add a decision step that sends the workflow down one path or another, for example when an amount is over your approval limit or a status changes.
Wait before continuing
Pause a workflow for a short, set time before the next step runs, and learn when a schedule is the better way to wait hours or days.
Loopfour