Loop
Last updated
Last updated
The Loop tool allows you to iterate over each item in a list and pass variables that represent values based on which loop action you've selected. There are currently 4 different ways to use a loop in a workflow.
To iterate over specific items in a payload (information from the trigger or actions), use the Variables menu {+} to select the item.
In 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.
All results from the loop action can be referenced in future steps of the workflow via the variable selector {+}.
The basic Loop action will repeat the next step in your workflow for each value identified in the item's list that you're referencing.
The example above is from our Send Shopify orders to Google Sheets template. After an order is created, MESA will go through each line item (product) in the order and create a Google Sheets row for each product on the order.
The Loop Sum action will calculate the sum of all items that match a specific criteria. The required fields for this action are:
Values to loop over - The items that you want to reference from a payload.
Field to add up - The resulting value to add up for the items you're referencing.
The optional Filter by fields in this action will allow you to specify conditions to add up only specific items from the list you're referencing.
In the example above, the Loop Sum action will 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.
The Loop Map action will create a list of values that are identified based on the item you're referencing from a previous step or payload. The required fields for this action are:
Values to loop over - The items that you want to reference from a payload.
Field to use - The field that you want the values to represent based on the items you're looping over.
The optional Filter by fields in this action will allow you to specify conditions to only pass certain field values relating to the items from the list you're referencing.
In the example above, the Loop Map action will pass text values for all line item (product) titles in an order. The variables that are passed to future steps will be available in two formats:
Comma Separated - The resulting values displayed as a string of text separated by commas.
Items - The resulting values as individual values in list form.
We recommend entering a custom variable for this: {{loop.items}}
The Loop Number of Matches action will return the number of items that match a specific criteria. The optional Filter by conditions are useful in this action.
In the example above, the Loop Number of Matches action will provide an integer as a variable that can be referenced in future steps representing the number of line items (products) in an order with an SKU that contains the letters "SUB".
You can do this by clicking Edit Code on the Loop step and going into the code.
In the code editor, you can change the sum line.