Working with Subflows

To create an empty Sublfow template as part of the main Flow, click subflow in the Templates tab (1). The empty template will open in a separate tab next to the main Flow tab. The Subflows you create will automatically appear as templates in the list of Step templates in the Templates tab (2). To add them to the main Flow tree or reuse them, drag and drop them onto the Canvas.

On the main Flow tree, the Subflow Steps will be grouped into a block for easier navigation through the Flow (3).

Set up Subflow

Inbound parameters

When implementing Subflows that use data from the main Flow, pass the data using inbound parameters. An inbound parameter is an internal variable specific to the current Subflow, which receives its value from the main Flow. Using inbound parameters makes working with Subflows predictable, as you know what data they contain.

Alternatively, you can set up Shared Merge fields in the main Flow, similar to Triggered Flow's functionality. However, we do not recommend using this option, as with this approach, the Merge fields become accessible not only within the current Flow but also across all Flows within the Bot, making refactoring more difficult. Consequently, this approach complicates the reuse of Subflows, as Shared Merge fields depend on the context in which they are used.

Set up

Once you click subflow in the Templates panel, the empty Subflow will open in a separate tab. You need to configure your Subflow from within both the Subflow and the main Flow.

First, in the Subflow tab to the right, provide:

  1. Subflow name as it will appear in the list of all Step templates in the Templates tab (1).
  2. Name of the Inbound parameters that the Subflow expects to receive from the main Flow (1).
    Note how the name of the inbound parameter from image (1) is displayed in the main Flow on image (2).

TIP

If you add an inbound parameter (ex., "a") along with a Merge field (ex., "test"), the parameter will be listed as "test.a" from the Merge field list {x} inside the current Subflow only.

  1. Merge field settings: name and type (to use within the current Subflow).
  2. Exits: define through which exits the Subflow will exit in the main Flow.
  3. Provide an output example, if necessary.

From within the main Flow:

  1. Drag and drop the Subflow template from the Templates tab onto the Canvas.
  2. Select the Subflow block on the tree and provide its name.
  3. In the Details tab, provide a variable to the inbound parameter you have defined earlier.
  4. Provide the Merge field name to the Subflow block to later use its result in the solution.

Once you have finished the setup, save and activate the Flow. Clicking Activate from both the main Flow and its Subflows activates the entire solution.

TIP

Inbound parameters and exit names must be unique within the current Subflow. The use of "Error" and "Timeout" as exit names are prohibited, as these are reserved for system exits. The Subflow will exit through default Error and Timeout exit legs as defined in the Error Handling section of the main Flow.

Return result from Subflow to main Flow

The Subflow result exists only in the form of a Merge field. Use the Return subflow result Step template to pass the Subflow result to the main Flow.

TIP

You don't need to download the Return subflow result Step template from the Library. It is automatically added to the Templates tab when you create a Subflow.

In this Step template, provide:

  • Subflow exit that defines the leg through which the Subflow will exit in the main Flow.
  • Results that contain the Subflow's execution result that you will later use in the main Flow by calling the Subflow's Step Merge field.

TIP

If your main Flow logic continues after the Subflow logic, using the Return subflow result Step at the end of the Subflow tree ensures the logic continues. Skipping this Step in the Subflow will result in the Flow logic ending with this Subflow.

To pass the Subflow's result that contains some custom data/unified data from different Steps, use the Create Merge Field Data Step template and place it before the Return subflow result Step on the Flow tree. Once done, provide a valid Output example in the Subflow output section that corresponds to your data format. The values defined in the Output example are available outside the current Subflow in the Merge field section {x} under the current Subflow block's name.

TIP

In case you are using the Create Merge Field Data Step, make sure that the names of the properties you have defined in the Output example match with those used in the Create Merge Field Data Step.

You can use the same exit in the Return subflow result Step template multiple times. Your Subflow logic can have many branches and options exiting dozens of legs. But as a global result of the Subflow execution, you can map those legs to fewer exits when working on the main Flow level.

TIP

The Go to Step in the main Flow can redirect to the Subflow.

Merge field visibility

In the main Flow:

  1. Session and Thread Merge fields are visible within the main Flow only.
  2. Global and Shared Merge fields are visible in both the main Flow and any Subflow within the account.
  3. The Merge field result of a Subflow is visible within the main Flow.

TIP

The main Flow's Shared/Global Merge fields are visible inside its Subflow without the data that is transferred via the Subflow's parameters.

In the Subflow:

  1. Session and Thread Merge fields created in a Subflow are visible within the current Subflow only.
  2. Shared Merge fields are visible within triggered Flows and Global - within the Bot.

Error handling

The concept of error handling is similar to the one the Steps have. All errors within the Subflow will be returned to the main Flow and will be handled there. The Subflow will exit through the Error/Timeout legs in the main Flow. Alternatively, you can configure the Handle Flow error Step in the main Flow to handle all errors in both the main Flow and its Subflows.

Reopen Subflow

To reopen the Subflow, select the Subflow block on the main Flow tree and then click the Step template name in the Details tab. Or click Edit next to the Subflow template in Templates list.

Clone/Delete/Reuse Subflow template

To clone or delete the Subflow, click the respective buttons in the Subflow tab.

TIP

You cannot delete the Subflow if it is a part of the main tree or another Subflow.

To reuse the Subflow, drag and drop its template onto the Canvas from the Templates tab.