Using Sub-Flows/Child Processes

Last Updated: 08/12/2016 Introduced in Verision: 2.0

When using the Flow Designer, it is possible to embed another flow as a step in your parent flow by adding it from the list of available components. This is referred to as adding a “child process” or a “subflow.”

Subflows are added to the Flow Designer by dragging and dropping a step for the flow from the Flows category in the Toolbox. A parent flow will initiate a child flow upon reaching that step in the process and wait for the child flow to complete before moving forward.

To not wait for the child flow to complete before moving forward, use the Start Linked Flow Async (or Fire and Forget Linked Flow) method of calling a subflow; this will invoke the subflow and immediately return control to the parent flow. For more information on this method, see the Invoking Asynchronous Sub-Flows/Child Processes documentation topic.

 Screen shot 2014-06-19 at 4.27.37 PM
 

 

For many applications, making sub-flows of frequently used steps (such as sending an email, saving an article, creating an alert, or for performing error handling) simplifies your application’s design. It makes your application easier to maintain, since a change in the sub-flow will be reflected in all parent flows. It also helps to unclutter your Flow Designer’s workspace and keep the focus on what key processes are distinct to each flow. 

A sub-flow contains all steps, inputs and outputs, to perform a certain function, and can be used as a single step in multiple flows. When an object’s data is contained and hidden in the object, programming languages refer to this as encapsulation

Example 1

Video: http://www.screencast.com/t/RgzpdRbWHzg 
 
This video shows calling a child process to perform a custom action of “feeding multiple ducks.” A process data folder is created for each duck fed to demonstrate how to record process data as child data of a parent process. 

Example 2

In the example, we will:

  1. Edit a Create Insurance Policy flow, which already contains a form and a folder extension data type Create Policy step.
  2. Introduce an Error Handling subflow, which already exists.
  3. Introduce a Catch Exception step.
  4. Map the outputs from the Catch Exception step into the Error Handling subflow.

Begin by navigating to a Designer Folder, and opening our existing Create Insurance Policy flow.

The Flow Designer opens, showing the Insurance Policy Request form and the Create Insurance Request step.

oldFlow

 
The output from the form is mapped to the Create Insurance Request step.
 
In the Components panel, expand the category Flows. Inside is a tree containing flows available to be embedded as sub-flows. Expand the folder in which the Error Handling flow exists. Drag and drop the Error Handling flow into the workspace. In our example, the error handling flow simply contains a form that tasks a Portal Administrator with handling the error. The form uses form labels to show the error information generated from the Catch Exception step, which we will introduce next.
 formPreview
 
 
Expand the Flow Management component category in the Toolbox panel.
 
Drag and drop the Catch Exception component into the workspace. Connect the steps as follows:
 
 flowConnected6
 
Now, all that is needed is to map the data collected from the Catch Exception step into the Error Handling Flow.
Click on the Error Handling flow and from the Properties panel, click Show Mapping Editor. Next, drag anchors from the data elements outputted by the Catch Exception step to their respective input nodes on the Error Handling Flow step.
 mappingEditor
 
 

Click OK to save and close the Mapping Editor. Now, if an exception is caught, the sub-flow will execute. This method of invoking a flow will cause the main parent flow to remain in a wait state until the subflow completes, which may not be the desired behavior. To cause control to immediately return to the parent flow upon invoking a subflow, use the “Fire and Forget” method of calling a subflow.

The “Fire and Forget” method of invocation calls a flow in an asynchronous manner. For more information see the Invoking Asynchronous Sub-Flows/Child Processes documentation topic.

 

 

Additional Resources