How to set up and use a Loop
Run actions over a list of items. Follow these steps:
*This is a very advanced feature. Reach out to our team and we'll help you set it up!
Prerequisites and example:
*You will need to have a List variable to be able to use a Loop. You can get/create a List in a few ways:
Using the Extract Information block, you can extract a field and select List? as checked
Coming soon: Input lists in the trigger, other actions that will 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.
To create the list variable needed for the loop, we'll have a manual trigger with a text input (in this case "List of URLs"). *Variables are inputs from the trigger, or outputs from previous steps.
Then, we'll have an Extract Information block where the Field Label is URL, Description of data to extract is "Separate the URLs from the list", and then we'll check List?
Add a Loop action: While editing a workflow, click the plus 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.
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.
Select the List of Items to Loop Over: Choose a variable with the type "List".
β*You will need to have a List variable to be able to use a Loop as explained in the callout above.Add actions within the Loop: Click the plus 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 "Extract URL List -> URL" 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 "Iterator" section of the variable selector.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.
Customize Output (optional): Return to the Loop's settings and toggle on Customize Output. You can either click on the loop to open the settings, or click the "Customize Output" button at the bottom of the loop action.
By default, the output of the loop will be a concatenated/merged version of each individual loop and all the outputs of its steps. By toggling this on, you can specify the output format and the separator.
The output format lets you 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.
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.Run the workflow: You can run the workflow (in this case you can see there are 3 URLs separated by a comma).
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: