Loop

Last update: Edit

1 Introduction

A loop is used to iterate over a list of object and perform actions on each item of the list when building microflows. For example, you can retrieve a list of orders from your database, then loop over this list and mark orders as processed. For more details on use cases, see the Configuring a Loop section.

The loop is visualized as a frame. The flow inside the loop is executed for each object. That means, if you add more than one activity to the loop, the full flow gets executed on each item. For example, you can add a loop that will prevent orders from processing if the order is not paid:

The loop can contain all types of elements used in microflows, except for start and end events. Additionally, only a loop can contain break events and continue events. A break event is used in loops only to stop iterating over a list of objects and continue with the rest of the flow in a microflow. A continue event is used in loops only to stop the current iteration and start the iteration of the next object.

2 Loop Properties

Loop properties consists of the Data Source section and are described below:

  • Loop Over – a variable that is a list of items you will loop through

  • Loop Variable Name – refers to the name of the list item that is currently being worked on

    Data Source Properties of a Loop

3 Configuring a Loop

A straightforward use-case is where you retrieve a list of orders from your database, loop over this list, and mark orders as processed as a result.

Loop Example

Make sure you have the following prerequisites:

  1. Create an entity in your domain model and name it Order.
  2. Create an attribute of the Boolean type for this entity to indicate the status of an order and name this attribute Processed.
  3. Create a microflow.

To start the use-case, do the following:

  1. Open a microflow you want to add a loop to.

  2. First of all, you need to get the list of orders to loop over. Do the following:

    a. In the Toolbox, select Retrieve, drag and drop it to the microflow.

    b. In Properties > the Data Source section, select From Database, and set Order as an entity for this activity. (The Range property is set to All by default):

    Retrieve Object Properties

  3. As you have retrieved the list of orders you can work on, you now need to create a loop and logic for it. Do the following:

    a. In the Toolbox, select Loop, drag and drop it to the microflow.

    Loop is Added

    b. In Properties, set OrderList as Loop Over (Loop Variable Name is set automatically). So, you have selected the list of objects to loop over.

    Loop Properties in an Example

  4. Now you can add the activity that will change the status of each order to Processed. This means that the activities you add inside the loop will be performed on each object (each order). Do the following:

    a. In the Toolbox, select Change Object, drag and drop it inside the loop .

    b. In Properties > the Data Source section for the Change Object activity, set Object to Order.

    c. When the Change Members option appears, click Add New Value.

    Change Object Properties in Loop Example

  5. In the Change value dialogue window, do the following:

    a. Set Select an Attribute or Association to Processed (Boolean).

    b. In the Expressions tab, set the New value of this attribute by typing in true.

    Example of Change Value Dialogue Window

    c. Click Add to save the changes.

This video shows the process of configuring the example above:

As a result, you have a list of orders retrieved to your microflow, and a loop that iterates over this list. The activity inside the loop sets the status of each order to processed.

4 Read More