Looping a flow or a subflow

To loop a flow or subflow, you define exception handlers and exit codes for looping in the Flow Attributes. You then define in the Completion Attributes to determine the flow state according to the exit code of the last failed work item or the last successful work item.

About this task

You can define a flow or subflow that loops until a specific condition is met, such as the exit code of a work item in the flow. This is useful to rerun a group of jobs until you achieve specific results.

By default, an exit code of 0 indicates success. Any other exit code indicates failure, unless you define other non-zero success exit codes in the work item.

You can define that the flow get its exit code from the last finished work item if the flow is successful, or the last failed work item if the flow failed.

For example, you have a flow with three jobs: Get_Data, Refine_Data, Examine_data.
Simple flow with three jobs: Get_Data, Refine_data, Examine_Data

You want the flow to rerun until the exit code of the last job Examine_Data is 0.

You also want the flow exit code to inherit the exit code of the last successful work item if the flow was successful or the last failed work item if the flow failed.

Procedure

  1. In Flow Editor, select Edit > Flow Attributes.

    The Flow Attributes dialog is displayed.

  2. Select the Exception Handling tab and click Add.
  3. Define your conditions.

    In the following example, we defined that the flow is to rerun until the job Examine Data has an exit code of 0. The maximum number of times it can rerun is 30:

    Exception Handler Definition window with work item Examine_Data with an exit code of 0
  4. Click OK.
  5. To have the flow inherit the exit code of the last successful work item for a successful flow or the last failed work item for a failed flow, define the flow's Completion Attributes.
    1. Select Edit > Completion Attributes and select as shown to have the flow inherit the exit code of the last work item that succeeded or failed.
      Flow Completion Attributes window
  6. Select Flow Definition > Save Draft to save your changes.

    If your flow is inserted in another flow, the subflow icon changes to indicate that this subflow will loop, as follows:

    DataRefine icon, indicating the flow loops
    Note:

    The flow you define here will always loop under the specified circumstances, even when embedded in another flow as a subflow.

    Any work item that depends on the DataRefine subflow cannot run until the looping completes.