Processing Subflows
You can reuse flows with SubFlow components. SubFlow components invoke subflows, flows that execute as a subroutine in a parent flow. See below for guides to invoking subflows and processing data with subflows.
- See Also
- To find the parent flows that invoke a subflow, right-click a flow and click Search Flow References. For details on the search results, see Searching References > Searching for Flow References in the Flow Designer user's guide.
Creating and Invoking Subflows
See below to create a subflow and invoke a subflow from a parent flow.
Adding a Subflow
To add a subflow to your flow, you can drag and drop a flow from the tree pane onto the workspace. Or, add a SubFlow component
from the Control tab of the palette and set the component's Flow property.
Starting and Ending Subflows
You can create a subflow to reuse almost any part of a flow. You must start a subflow with the Start component. End a subflow with any end component, except for the NextFlow component.
Configuring Transactions for Subflows
You can execute a flow as a single transaction. You can also execute subflows in the same transaction or a separate transaction.
To execute a subflow in the same transaction as the parent flow, set BeginTransaction to true for the parent flow's start component. To execute subflows in a separate transaction, see below:
| Flow | BeginTransaction |
|---|---|
| parent | false |
| subflow | true |
- See Also
- See Transactions in the More Topics section for an introduction to transactions in the Flow Service.
Passing Inputs to Subflows
You can pass data to subflows by connecting a stream or using flow parameters.
Configuring a Subflow's Input Stream
To process a stream with a subflow, you need to configure the start component's output stream in the subflow to match the output stream of the component that you connect to the SubFlow component.
To select the stream type, click the label next to the start component. To define the stream fields, select the start component. You can then define the stream fields in the Stream pane.
If you're not processing the input stream, set the start component's stream type to "Any."
Note
The Flow Service will raise an error if the stream types don't match. To avoid an error, you can set the stream to "Any."
- See Also
-
- See Stream Definitions in "More Topics" to configure the fields for different types of streams.
Passing in Flow Parameters
Flow parameters provide a mechanism to inject values from the parent flow to the subflow, setting values for the public flow variables that you define in the subflow.
Defining flow parameters
To define a subflow's flow parameters, define public flow variables in the subflow on the Variables tab. When you set the Flow property for the SubFlow component, the Flow Designer automatically updates the flow parameters on the SubFlow component's Param tab and sets the flow parameters' default values to the default values you defined for the public flow variables in the subflow.
Setting flow parameters
You can set flow parameters on the SubFlow component's Param tab. Or, you can use a Mapper to dynamically set the flow parameters: Connect the mapper before the SubFlow component. Double-click the mapper and in the mapping window connect the output fields in the Component Properties section under the Param node.
Updating the SubFlow component
If the subflow's in a different project than the parent flow, you need to manually update the SubFlow component when you change the flow parameters in the subflow. Right-click the SubFlow component and click Update SubFlow Information. You can use the wizard to select the flow parameters to update.
- See Also
-
- To sync other changes, see Subflows > Updating the SubFlow Component in the user's guide.
Priority for setting flow parameter values
The flow parameter are treated as flow variables in the subflow. Set operations overwrite the values of the flow variables in the subflow according to the following priority:
- Setting defaults for flow variables: When you set a default value for the public flow variable in the subflow, this default value is only used if a flow parameter value can't be passed in for some reason.
- Setting values in the Param tab: The value you set on the Param tab overwrites the default you set for the public flow variables in the subflow.
- Setting values in the Mapper: When you connect a field in the Mapper, the Flow Designer replaces the value in the Param tab with a placeholder.
Returning Subflow Output
See below to access the subflow's output in the parent flow:
- Returning a Stream
- Returning Public Flow Variables
- Getting and Setting Subflow Return Values
- Passing through Input Streams
Returning a Stream
You can end a subflow with an EndResponse component to output the stream to the parent flow. See below for notes on designing subflows that output streams.
Updating the SubFlow component's output stream
If you change the stream type or field definitions of the subflow's output stream, you need to update the SubFlow component's output stream: right-click the SubFlow component and select Update Subflow Information.
- See Also
-
- To sync other changes, see Subflows > Updating the Subflow Component in the user's guide.
Connecting subflows with multiple end components
You can end a subflow with multiple end components on parallel branches. See the following notes to connect the SubFlow component's output stream in this scenario.
If all the end components output the same stream type and stream fields, the SubFlow component's output stream shares the same stream type and fields. Otherwise, the SubFlow component's output stream type is Any: if multiple end components output streams with different stream definitions, or if the subflow ends on a component that doesn't output a stream.
If the output stream type is "Any," a stream type isn't defined. You can't connect these streams to components that need to process a specific type of input stream.
Returning Public Flow Variables
The SubFlow component outputs stream variables that correspond to the subflow's public flow variables. You can get the values in the Mapper:
- In the parent flow, connect a Mapper to the SubFlow component's output stream and double-click the Mapper to open the mapping window.
- In the Stream Variables section in the input fields, under Stream Data, connect the stream variables.
Getting and Setting Subflow Return Values
You can output string values from a subflow to the parent flow:
- In the subflow, set the end component's ReturnValue property.
- In the parent flow, connect a Mapper to the SubFlow component's output stream and double-click the Mapper to open the mapping window.
- Under the Component Properties section in the input fields, connect the SubFlow component's ReturnValue property.
Note
If you end the subflow with an Exception component, you can reference the SubFlow component's ReturnValue property to get the exception message.
Passing through Input Streams
You can use SubFlow components to invoke flows that process data but don't return a stream that contains the results. If the subflow doesn't output a stream, the SubFlow component passes through the input stream. You can also set the SubFlow component's StreamPassThrough property to true to output the input stream, regardless of whether the subflow outputs a stream -- the SubFlow component ignores the subflow's output stream.
See below for guides to connect SubFlow components and return flow variables when you're not returning a stream.
Connecting SubFlow components with stream pass-through
You can connect a Mapper after the SubFlow component to get the values of public flow variables that the subflow sets.
Configuring pass-through
You can set the SubFlow component's StreamPassThrough property to true, or you can execute a flow that doesn't output a stream as a subflow. For example:
- End the subflow with an End component.
- Use the Break component to break out of a loop.
- Use the Exception component to throw an error and end the subflow immediately.
Returning flow variables using pass-through
When you're passing through the input stream, the SubFlow component sets stream variables in its own input stream. You can connect a Mapper to get the stream variable values:
- Connect a Mapper to the SubFlow component's input node and double-click the Mapper to open the mapping window.
- Connect the stream variable in the Stream Variables section of the input fields, under Stream Data.
Passing a stream to multiple subflows
When you're using stream pass-through and connect multiple SubFlow components to the same component, using parallel branching, all the SubFlow components set stream variables in the same input stream. As the parallel branches execute in sequence, each SubFlow component adds new stream variables to the same stream. And, if a stream variable with the same name already exists in the input stream, the SubFlow component overwrites the value.
If you want to get all the public flow variables that all the subflows set, set StreamPassThrough to false for each SubFlow component and use EndResponse components in the subflow to output unique streams for each SubFlow component.
Or, set unique names for the public flow variables in each SubFlow component you connect to the same input component.