Loop a flow or subflow

About this task

You can define a flow or subflow that loops a specific number of times or loops until a specific condition is met. This is useful if you need to rerun a group of jobs until you achieve specific results.

In this example, John needs to run a series of three jobs that need to be repeated until the correct data results—an undetermined number of times. John created the following flow called DataRefine:

Process Manager allows you to automatically rerun a flow or subflow whenever a particular work item in the flow has a specific exit code. This allows John to loop DataRefine as many times as required to complete refining the data results. In the script run by the job Examine_data, John sets the exit code of the job to be a particular value, such as 77, until such time as the data refinement is complete. Then the exit code of Examine_data is set to 0. John used the exception handling at the flow level to loop the flow, as follows:

If John requires it, he can use the number of times the flow is rerun in his job. This information is available through the built-in variable JS_ITERATION_COUNTER[flow_name], where flowname is the name of the flow, without the user name. For example:

JS_ITERATION_COUNTER[myflow:subflow]

To loop a flow:

Procedure

  1. Define the jobs in the flow.
  2. Ensure that one job in the flow sets a specific exit code in the circumstances under which you want to rerun the flow. Ensure that it sets a different value when the flow should stop rerunning.
  3. Set the automatic rerun exception handler to rerun the flow under the correct circumstances:
    1. Right-click in an empty space in the flow definition, and select Flow Attribute.
    2. Click Exception Handling.
    3. Click Add. The Exception Handler Definition dialog appears.
    4. In the Exception type field, select A work item has exit code...
    5. In the Work item field, ensure the correct work item is selected.
    6. In the Has exit code field, specify the exit code conditions required to loop the flow.
    7. In the Action field, ensure Rerun is specified.
    8. If applicable, in the After field, specify the number of minutes to delay the rerunning of the flow.
    9. In the Maximum number of reruns field, specify the maximum number of times you want the exception handler to rerun the flow.
    10. Click OK. The exception handling specification is added to the list. Click OK again.

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

Loop a subflow that does not contain a loop definition

Procedure

  1. Add the subflow at the appropriate location in your flow.

    Note: You still need to ensure that one job in the subflow sets a specific exit code in the circumstances under which you want to rerun the flow. Ensure that it sets a different value when the subflow should stop rerunning.

  2. Right-click on the subflow icon, and select Attributes.
  3. Click Exception Handling.
  4. Click Add. The Exception Handler Definition dialog appears.
  5. In the Exception type field, select A work item has exit code...
  6. In the Work item field, ensure the correct work item is selected. By default, it is the last work item in the flow.
  7. In the Has exit code field, specify the exit code conditions required to loop the flow.
  8. In the Action field, ensure Rerun is specified.
  9. If applicable, in the After field, specify the specify the number of minutes to delay the rerunning of the flow.
  10. In the Maximum number of reruns field, specify the maximum number of times you want the exception handler to rerun the flow.
  11. Click OK. The exception handling specification is added to the list. Click OK again. The subflow icon changes to indicate that this subflow will loop, as follows:
    Note:

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