Loop
Last updated
Last updated
The Loop tool allows you to iterate over a list of items one-by-one.
A Loop is useful when you want to take a list of things, for example, all of the line items in an order, and perform an action on each individual item.
To iterate over specific items from a list (typically from the Trigger or Actions), use the variables menu to select the list of items after adding your Loop step.
After your Loop has been added and configured, you'll see Loop and Loop End steps within a confined container with a grey border.
To perform one or more tasks on each item in the list, add actions between the Loop and Loop End steps.
You can reference the individual items or their information by using the Loop variables that will populate for actions added in between the Loop and Loop End steps.
You will have variables available from steps that occur prior to the Loop in your workflow, as well as the Loop variables. Typically, you'll want to use Loop variables when configuring actions between the Loop and Loop End steps.
Be sure to Save your workflow after adding and configuring your Loop to see your available Loop variables.
In the Configure menu of each Loop action there are conditions you can add to filter the list.
You can populate the Filter by conditions via the More options button so that specific values or results that meet the conditions are passed to the following steps.
The Loop End step signifies the end of the Loop.
Actions added after the Loop End step will only run once.
The default configuration of the Loop End step is to continue the workflow without passing variables after the Loop. However, you can optionally configure the Loop End step to use Loop and Map Value.
In the Configure submenu of the Loop End step, click the More options button to add Loop End Behavior to the step. After that, click the Loop and Map Value radio button and select a value to return in the field via the variable selector.
The value can be a single variable from an action within the Loop, or you can add a Transform Mapping action within the Loop and map a new object.
The variable that's created from the Loop End step will be Loop End > Items, and it can be used in steps after the Loop.
Beyond the regular Loop action, you can add different variations of Loop actions to your workflow. These are single-output steps with a different behavior than the Loop & Loop End functionality.
The Loop Sum action will calculate the sum of all items that match a specific criteria.
For example, the Loop Sum action can add up the price of line items (products) in an order and pass that value as a variable to reference in the following steps. The value will be an integer.
Optionally, you can customize the sum operation by clicking Edit Code link and going into the code.
In the code editor, you can change the sum line.
The Loop Map action will create a list of values that are identified based on the item you're referencing from a previous step.
For example, the Loop Map action can pass all line item (product) titles in an order for tagging purposes.
The Loop Number of Matches action will return the number of items that match a specific criteria.
For example, the Loop Number of Matches action can provide an integer as a variable that can be referenced in future steps representing the number of line items (products) in an order with a specific SKU.
The Loop queue is synchronous.
There is a legacy version of the Loop step that can be found on stores with previous versions of MESA, or when using templates that have not been updated to the latest Loop and Loop End functionality.
Everything gets enqueued all at once with legacy Loop actions, which makes this action more susceptible to timeouts.