Skip to main content

Loop

Jake Rosenthal avatar
Written by Jake Rosenthal
Updated today

How to set up and use Loop action

Run actions over a list of items. Follow these steps:

*Loop is an advanced feature. If you want help setting it up for your use case, reach out to our team.

Prerequisites and example:

You will need to have a List variable to be able to use a Loop. You can provide this list in two ways:

  1. Select an existing List variable (for example, a List from a trigger input or previous step),

    OR,

  2. Enter hardcoded items or variables.

If you want to select an existing List variable, you can get/create it in several ways:

  • Using the Extract Information block, you can extract a field and select "List?" as checked

  • Trigger inputs that have "Allow multiple values" enabled

  • Run Code actions that output lists

  • Structured outputs from other actions

  • Other actions that automatically output a list when there are multiple records returned

For the purpose of this help article, we'll go through an example. We will be creating a newsletter generator that takes in multiple URLs to blog posts that will be summarized and presented in newsletter style.

  1. Add a Loop action: While editing a workflow, click the “+” button between existing blocks.

    This will open a modal where you can select from Cassidy's pre-configured actions. Choose the Loop action to add it to your workflow.


    This is the interface when you have added the loop action in your workflow.

  2. Rename the action (if needed): If you want to make the action more descriptive or easier to reference as a variable later, enter a new name.

    Click on the three dots in your Loop Action “…” and click rename.


    Rename the action to make it easier to reference later as a variable.

  3. Select the List of Items to Loop Over: In “List of Items to Loop Over”, you can either select an existing list variable or manually input list.

    1. To select an existing List variable, click the field and choose “Select a variable”.


      *You will need to have an existing List variable to be able to use a Loop as explained in the callout above. Here, we have selected previously created manual triggers.

    2. To enter hardcoded items or variables, click the pencil icon. You’ll see a box with the placeholder “Enter a value”. Type an item, or click “#” to refer to a variable, then click “Add”. Repeat to add more items.

  4. Add actions within the Loop: Click the “+” button inside the Loop action to add actions within the Loop. For each item in the list, these actions will be run. For example, if your list contains 3 URLs, it will run the Loop 3 times, once for each URL in the list.


    In this example, a Scrape Webpage action has been added. To pass the individual URL, select the variable "Current item in URL". It will be under the "Loop" section of the variable selector.

  5. Continue adding actions: Add as many actions as you want within the loop. Again, each item in the list will go through each of these actions.

  6. Customize Output (optional):


    In “Loop Output”, choose how results are returned:

    • Default: By default, the output of the loop will be a concatenated/merged version of each individual loop and all the outputs of its steps.

    • Custom Text: Specify the structure used to combine results from each action in the loop into a single output. This output will then be combined for each item in the list. In the newsletter example, this is essentially what each URL should return (a summary of the blog along with its category and a link).

      • The separator is the delimiter to place between individual loop results when merging them together. In our example, this is the set of blog summaries separated by a dashed line. You can choose between New Line, Dashed Line, and Comma-Separated.

    • Select Specific Variables

      • Choose which variables to return as lists.

      • Each variable you select is returned as a list, with one value per loop iteration (in order).

      • This is useful when you want a clean list of outputs to use later (for example: titles, URLs, IDs, or files).


      With the “Select Specific Variables” option, you can have it return the generated files (e.g., one PDF per iteration in the Loop). It's very convenient for making lists of files.

  7. Use the Loop's output: If you want to use the output of the loop, you can add an action after the loop and reference the loop's output. For example, in our case, we can add a Generate Text action to write the intro for our newsletter. You can reference the Loop output (the 3 merged/combined blog summaries) as a single variable.


    To finish the example, a Combine Text action was added to be able to combine the intro and the summaries from the loop.

  8. Run the workflow: You can run the workflow (in this case you can see there are 3 URLs).

Here's a sample of the final output:

Here's a sample of what each loop provided:

You can check by clicking the numbered icon and then opening each loop where you'll see the result and output of each action within each loop:

Did this answer your question?