Loop

The Loop by MESA app 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.

Overview

To iterate over specific items in a payload (information from the trigger or actions), use the Variables menu {+} to select the item.

If the payload itself is an array (such as a list of Shopify Customers) the variable will need to be manually entered as the key of the Get List step which can be found in the settings of the step. For example: {{shopify_1}}In each Loop action there are conditions you can add to filter the list by populating the Filter by sub-menu 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 {+}.

Loop

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.

Loop Sum

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 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 that contain "Summer" in their title and pass that value as a variable to reference in the following steps. The value will be an integer.

Loop Map

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 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 items (products) in an order that contain "3-pack" in the title. 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}}

Loop Number of Matches

The Loop Number of Matches action will return the number of items that match a specific criteria. The 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".

How can you do a math operation on a value inside of the Loop Sum step

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.

Last updated