If you haven't worked with Workflows before, check out our Getting started with Workflows guide
Introducing Workflow loops
Workflow loops allow you to repeat a step multiple times for all values in a multi-valued custom field or expression.
Adding a Workflow loop
To add a Workflow loop, simply click "Add a step" and then choose the "Create a loop" option.
Returning to the main workflow screen, you will see a new loop block has appeared in your steps.
Selecting a resource to loop over
The "Select a variable" dropdown will give you available resources you can loop over. This can be one of:
A multi-select custom field
An expression that returns a list of values.
Adding steps to a Workflow loop
Once you've picked what you want to run your steps over, you can add Workflow steps to your loop using the "Add a step to this loop" button.
This works just like adding a regular workflow step, and you can reference the value you are looping over in the step - you'll find these at the top of any relevant menus, prepended by "Each". In this example, we are looping over the custom field "Impacted surface":
You can add as many steps as you would like to a loop and re-order them by dragging and dropping, just like steps. They cannot be moved out of the loop, though.
How often will workflow loops run?
Workflow loops function slightly differently to regular workflow steps - if the custom field or expression you are looping over changes, the loop will run its steps on any new values.
Let's elucidate this with an example:
Imagine you have set up a workflow to run once per incident, when the incident severity is critical or higher. You've got two steps:
Announce the incident in
For each team in the
Affected Teamscustom field:
Page the relevant escalation policy in PagerDuty
This workflow will function as follows:
A critical incident is declared, affecting teams
B. The workflow runs, posting the announcement and escalating following
Affected Teamscustom field is updated to now include team
The first step, posting the announcement, will not re-run, since it has already been executed for this incident. However, the second, looping step will "catch up" with the new
Affected Teamsvalue by escalating to