Orchestrator

Looping

Content is machine translated from English by Phrase Language AI.

Loops can be implemented within a workflow to repeat a set of tasks based on defined conditions.

Loops execute in sequence. A maximum of 4 steps can run in parallel.

Loop configuration is accessed in either the Advanced tab of a block configuration, or by right-clicking a block and selecting Edit loop.

Loop settings require a list of things to operate on:

  • Plain, single values, which are then usable in task parameters such as {{ @item }}.

  • A .JSON object where each element in the object can be addressed by its key such as {{ @item.key }}.

Accessing the aggregate results of a loop

The output of all iterations can be accessed as a .JSON array once a loop is completed. The output of each iteration must be a valid .JSON file.

There are four loop types that can be defined and are selected in the loop_with field:

  • withSequence

  • withItems

  • withComplexItems

  • withParam

withSequence

The withSequence loop enables an iteration over a sequence of numbers or the generation of a range of values within a workflow.

It can be used for repeating a set of steps a specific number of times or performing operations based on a range of values.

To create a sample withSequence loop, follow these steps:

  1. Select an empty block and open the Loop configuration.

  2. Click Edit loop.

    loop_with configuration options are presented.

  3. From the loop_with field, select withSequence.

  4. Enter the number of loop iterations to the Count field.

  5. Optionally, enter a value the loop should start from and/or end with.

  6. Click Save loop.

  7. From the Parameters configuration, click Edit parameters.

    Configuration options are presented.

  8. In the Message field, enter {{ @item }} and click Save parameters.

    This value will be converted at runtime.

For example, if count is set to 3 and the start value is 2, the results of this loop will be:

  • loop list => ["2", "3", "4"]

  • {{ @item }} => 2 or 3 or 4, based on the iteration

withItems

The withItems loop enables iteration over a list of items.

It can be used when needing to perform operations based on a list of items.

To create a sample withItems loop, follow these steps:

  1. Select an empty block and open the Loop configuration.

  2. Click Edit loop.

    loop_with configuration options are presented.

  3. From the loop_with field, select withItems

  4. Enter en in the variable field and click +Item (another variable field is created).

  5. Enter de in the second variable field and create a third field.

  6. Enter fr in the third variable field and create a fourth field.

  7. Enter us in the fourth variable field.

  8. Click Save loop.

  9. From the Parameters configuration, click Edit parameters.

    Configuration options are presented.

  10. In the Message field, enter {{ @item }} and click Save parameters.

    This value will be converted at runtime.

The results of this loop will be an iteration over a list of language codes:

  • loop list => ["en", "de", "fr", "ua"]

  • {{ @item }} => en or de .. ua

withComplexItems

The withComplexItems loop enables iterating over a list of objects.

It can be used when needing to perform operations based on a list of complex items.

To create a sample withComplexItems loop, follow these steps:

  1. Select an empty block and open the Loop configuration.

  2. Click Edit loop.

    loop_with configuration options are presented.

  3. From the loop_with field, select withComplexItems

  4. Click +Key:value to add a second key.

  5. For Object 1, enter the following:

    • Key: Value1

      • key (optional): name

      • (optional): Project 1

    • Key: Value2

      • key (optional): id

      • (optional): 11

  6. Click +Object to add a second object and +Key:value for a second key.

  7. For Object 2, enter the following:

    • Key: Value1

      • key (optional): name

      • (optional): Project 2

    • Key: Value2

      • key (optional): id

      • (optional): 22

    Settings sample:

    Loop_withComplexItems.png
  8. From the Parameters configuration, click Edit parameters.

    Configuration options are presented.

  9. In the Message field, enter {{ @item.name }} and click Save parameters. This value will be converted at runtime.

The results of this loop will be an iteration over a list of projects:

  • loop list =>

    [
      {
        "name": "Project 1",
        "id": 11
      },
      {
        "name": "Project 2",
        "id": 22
      }
    ]
  • {{ @item }} =>

    {
      "name": "Project 1",
      "id": 11
    }
  • {{ @item.name }} => Project 1

  • {{ @item.id }} => 11

withParam

The withParam loop enables iteration over a dynamic list which is output from any previous task or trigger.

This loop is just used as a reference in the parameter field.

Example:

Outputs of task (Strings: Publish a release):

{
  "created_at": "2015-01-28T09:52:53Z",
  "environments": ["development", "production"],
  "id": "abcd1234cdef1234abcd1234cdef1234",
  "locales": [
    {
      "code": "en-GB",
      "id": "abcd1234cdef1234abcd1234cdef1234",
      "name": "English"
    },
    {
      "id": "abcd5678cdef5678abcd5678cdef5678",
      "name": "German",
      "code": "de_DE"
    }
  ],
  "platforms": ["android"],
  "project": {
    "created_at": "2015-01-28T09:52:53Z",
    "id": "abcd1234cdef1234abcd1234cdef1234",
    "main_format": "xml",
    "name": "My Android Project",
    "updated_at": "2015-01-28T09:52:53Z"
  },
  "updated_at": "2015-01-28T09:52:53Z",
  "version": 1
}

If loop settings withParam is set with {{ $.locales }}, then:

  • loop list =>

    [
      {
        "code": "en-GB",
        "id": "abcd1234cdef1234abcd1234cdef1234",
        "name": "English"
      },
      {
        "id": "abcd5678cdef5678abcd5678cdef5678",
        "name": "German",
        "code": "de_DE"
      }
    ]
  • First {{ @item }} =>

    {
      "code": "en-GB",
      "id": "abcd1234cdef1234abcd1234cdef1234",
      "name": "English"
    }
  • {{ @item.code }} => en-GB

  • {{ @item.name }} => English

Or if {{ $.environments }} is referenced, then:

  • loop list => ["development", "production"]

  • {{ @item }} => development or production

Was this article helpful?

Sorry about that! In what way was it not helpful?

The article didn’t address my problem.
I couldn’t understand the article.
The feature doesn’t do what I need.
Other reason.

Note that feedback is provided anonymously so we aren't able to reply to questions.
If you'd like to ask a question, submit a request to our Support team.
Thank you for your feedback.