Scatter-gather
Split, transform, and merge lists of data with scatter and gather actions.
The scatter-gather pattern is a powerful way to process lists of data.
If you encounter lists of data (e.g. alerts, messages) in your workflows that you want to:
- Filter with a simple
if-condition
(see if-conditions) - Process one at a time: rename fields, create a case, etc.
We recommend first scattering the list of data into individual items, processing them one at a time, then gathering them back into a single list.
It’s almost always easier to deal with data one at a time than as a list!
After scattering, chain actions like you would in a workflow that processes one data point at a time. The output for every action between a scatter and gather action will be shown as N individual items in the workflow runs view.
Scatter
The scatter action takes a list of data and scatters it into individual items. Every action after a scatter action will be run for each item in the list.
Gather
The gather action ONLY works downstream of a scatter action. It will not work if you try to gather data that was not scattered.
The gather action takes a list of scattered data and gathers it back into a single list.
Scatter, filter, then gather
In this example, we’ll scatter a list of integers, filter out the odd numbers with a simple if-condition
on a reshape action, then gather the even numbers back into a single list.
Scatter
Scatter the list of integers into individual items.
Filter
Filter out the odd numbers with a simple if-condition
on a reshape action.
Set the inputs for the reshape action to:
And the if-condition to:
Gather
Gather the even numbers back into a single list.
Set the inputs for the gather action to:
Run workflow
Notice how the results for actions after the scatter action are shown as N individual items.