Skip to content

End Iteration v1.0.13 Help

Indicates the end of the iteration and returns the Flow to the specified Start Iteration Step within the Flow.

How can I use the Step?

You can use the Step with the Start Iteration Step to form a pair that controls loop and recursion logic within your chatbot Flow. In addition, the Step allows you to collect iteration data, which is helpful for data validation or capturing specific points during a loop.

How does the Step work?

The Step works as a loop control mechanism within a Flow. When reached, it returns the Flow to the Start Iteration Step specified in the Iteration destination parameter. If you need to collect iteration data during the Step execution, enable the corresponding toggle.

Prerequisites

To use the Step, make sure to meet the following requirements:

  • Basic knowledge of JavaScript/JSON.
  • A Start Iteration Step must be present and correctly configured in the Flow.

Iteration settings

To use the Step properly, place it on the iteration exit of a Start Iteration Step and do the following:

  1. For Iteration destination, select the Start Iteration Step you want the Flow to return to. This parameter is required.
  2. Optional: Enable Collect iteration data to collect data for each iteration that ends with the Step.

Merge field settings

By default, the Step has no Merge field and produces no output data.

If you enable Collect iteration data, the Merge field is available. The Step collects the iteration data, adding it incrementally to the Merge field. The collected data is available in the Merge field after completing the loop.

To learn more about Merge fields, their types, and how to work with them, follow this link

Output example

When you opt for collecting iteration data, the Step returns an array of objects containing data about each iteration that ended with this Step.

An object in the output array can have the following properties:

  • iteratedItemKey: Current index for arrays or key for objects.
  • iteratedItemValue: Current iterated value.
  • iteratedIndex: Number of the current iteration, starting from 0.

To make the Output example more relatable and better understand the data collection feature, let's consider an email validation example.

Use-case: Email validation

Suppose you're validating an array of email addresses. Your Flow has two exits for validation: valid and invalid. If an email is invalid, the Flow moves to the End Iteration Step, which is set to collect iteration data.

For instance, if you have the following array of emails:

json
["username1@gmail.com", "invalid email 1", "username2@gmail.com", "invalid email 2"]
["username1@gmail.com", "invalid email 1", "username2@gmail.com", "invalid email 2"]

The Step's output might look like:

json
[
  {
    "iteratedItemValue": "invalid email 1",
    "iteratedItemKey": 1,
    "iteratedIndex": 1
  },
  {
    "iteratedItemValue": "invalid email 2",
    "iteratedItemKey": 3,
    "iteratedIndex": 3
  }
]
[
  {
    "iteratedItemValue": "invalid email 1",
    "iteratedItemKey": 1,
    "iteratedIndex": 1
  },
  {
    "iteratedItemValue": "invalid email 2",
    "iteratedItemKey": 3,
    "iteratedIndex": 3
  }
]

Error handling

By default, the Step handles errors using a separate exit. So if any error occurs during the Step execution, the Flow proceeds down the error exit.

The Step throws errors for specific conditions:

  • If the iteration destination Step is not selected.
  • If the selected destination Step is missing in the Flow.

For more information on error handling, follow this link.

Reporting

The Step automatically generates Reporting events, allowing you to track its performance and user interactions.

To learn more about Reporting events, follow this link.

Service dependencies

  • studio v3.71.0
  • bot deployer v2.22.4
  • library v2.18.4

Release notes

v1.0.13

  • Add an option to collect iteration data
  • Rebuild external components with standard UI components
  • Improve error handling