Reference Guide

Detailed explanations of every feature and function in Nutshell

Loop

The Loop component allows you to loop through a record set, processing each record one-by-one until there are no records left. The record-set can come from either a Data component or a Connector.

Sreenshot

A simple app that loops through a mailing list, emailing each person one by one

For example, imagine that you’re building an inspection app that allows the end-user to create a snagging list, assigning tasks to specific team members. The Loop component would allow you to loop through each task one-by-one, sending an email alert to each team member so that they know what’s expected of them.

To use the Loop component, you really need to be fluent using the Data component to pull data out of a database table and push it to other components in your workflow. If you’ve never done this before, you might want to get your head around that first.

Assigning a Data-set to a Loop

Let’s assume that you’ve already set-up your database table and a Data component to pull out some records. You can add a Loop to your workflow by dragging it from the Data tool bar to your Canvas and linking your Data component to it.

Sreenshot

Data components can be mapped directly to a Loop on the Canvas

Now that you’ve added your Loop to the Canvas, you can map the output of your Data component to it. You do this by selecting the Data component, and editing its output mapping to assign the record-set to your new Loop. The Data componentGo to Data Component reference will tell you more about data mapping.

Creating the Loop

To create a loop, you need to create a workflow that will be followed for each record. For example, you might want to send an email for each record – in which case, your workflow would simply be an Email component.

Sreenshot

The Next Item link (success) creates the first step that will be followed when a new item is found

Create a Link from your Loop component to the next step in this workflow, as you would any other. With this Link selected, in the Properties panel, you’ll see two Link Outcome options:

  • Next Item (will be followed for each new item in the record-set)
  • No More Items (will be followed when there are no further items left)

Set your Link to Next Item. As long as your Loop finds another item in the recordset, it will follow this Link and send an email.

Closing the Loop

Once your workflow has completed, you need to close the loop – i.e. return to the Loop component to either go round again, or end the loop. In this example, once your email is sent, we need to Link the email component back to the Loop component to close it.

Sreenshot

Once an email is sent, the Success link takes the workflow back to the Loop for the next item

So in this example, for every record returned by the Data component, an email will be sent. After the email is sent, it will return to the loop to see if there are any more records left. Once all the records have been through the loop, the loop will end.

Ending the Loop

It’s important to specify what should happen once the loop ends and there are no further records in the data-set to process. We do this by linking out from the Loop again, but this time to whatever comes after the loop.

In this instance, we’re just going to end on a Screen that tells the end-user that the loop has completed. Add your Screen to the Canvas, and link your Loop component to it.

Sreenshot

The End of Loop (Failure) link from the Loop component is followed when there no more items left

With this Link selected on the Canvas, you’ll see again in the Properties panel two possible Link Outcomes:

  • Next Item (will be followed for each new item in the record-set)
  • No More Items (will be followed when there are no further items left)

This time, select No More Items and save your changes. This Link will now only be followed when there are no more items left in the data-set to be processed.

Warnings

The Loop component will fail to work if it’s not fully configured, and that means:

1. Assigning it a data-set from a Data or Connector component
2. Setting up a sub-workflow to follow for each item in the data-set
3. Closing the loop at the end of this sub-workflow
4. Creating a link out of the loop once all items in the record-set have been processed

If any of these things have not been completed, you’ll see a little warning triangle on the Loop component on the Canvas.

Sreenshot

Nutshell will warn you if you haven’t finished setting it up

Select the Loop component, and you’ll see in the Properties panel a message telling you what you need to do next to complete the configuration.

Loop Properties

Most settings for a Loop can actually be found within the Properties of Links leading in/out of the Loop component. When a Loop component is selected on the Canvas, the following settings are available in the Properties panel:

Basic Settings
Label An optional name, that appears on the Canvas. This makes reading larger workflows much easier.

Just getting started? Try the Tutorials section for handy quick-start guides.

Prefer to watch the action? Try our series of short video tutorials.

Can't find what you're looking for?

If you can't find the answer to your problem here, please contact Nutshell's support team via our dedicated help desk.