Invoke Another Workflow in the Solution
An automation solution typically includes multiple workflows. While there may be one main workflow, each workflow usually has one specific goal and one workflow may invoke another workflow to perform some operation. Callouts and event handlers may also invoke workflows.
Example
For example, the workflow below is used to produce a price quote for cleaning a room. The workflow a) calculates the area of the room based on its shape (round or square) and a single measurement (radius or side length), then b) calculates the price based on a per-square meter formula, and finally c) sends out a price quote by email.
The solution is better arranged using two workflows:
-
SendPriceQuote: This is the main workflow. The step Calculate Room Area invokes the CalculateArea workflow.
-
CalculateArea: This workflow calculates the room area based on inputs received from the SendPriceQuote workflow and returns the calculated area back to SendPriceQuote.
The CalculateArea workflow may be invoked by other workflows as well. For example, a workflow that calculates how long a job will take could invoke the CalculateArea workflow to perform the area calculation.
It is also possible to invoke external workflows published on the automation server. See Invoke a Robotic Workflow for Asynchronous Robotic Automation.
Steps
To invoke a workflow within your solution, you need to:
-
Configure the input parameters of the invoked workflow.
-
[Optional] Configure the timeout duration of the invoked workflow.
-
Use the invoked workflow's input parameters within the invoked workflow.
-
Set the return type of the invoked workflow.
-
Set the return value of the invoked workflow.
-
Invoke the workflow from another workflow, callout, or event handler.
-
Capture the response from the invoked workflow.
-
Manage workflow timing to ensure that the invoking workflow waits for the invoked workflow to end before continuing.
Configure the Invoked Workflow's Input Parameters
If the invoked workflow needs to receive information from the invoking workflow, you must define the invoked workflow's input parameters.
The workflow's input parameters can be modified after they have been configured, even if the workflow or its input parameters are already in use. See here.
To configure the invoked workflow's input parameters:
-
Open the invoked workflow.
-
Click Settings in the top-right corner of the canvas.
-
Click Input Parameters.
-
Specify the Name and Type of the input parameter.
-
Click to add another input parameter, or to remove an input parameter.
These parameters will be listed in the Assets Panel, under the workflow's Parameters group.
-
Click Save.
Configure the Invoked Workflow's Timeout Duration
In some applications, the invoking workflow must be able to react if the invoked workflow fails to complete. In the workflow settings for the invoked workflow, you can specify a timeout period - if the invoked workflow has not ended after the timeout period has elapsed from the time the invoked workflow started, then the invoked workflow's Timeout event is triggered. This event can be used in the invoking workflow to trigger an appropriate response, as shown below.
If no timeout is specified, or if the timeout is set to zero, the Timeout event will never be triggered.
To configure the invoked workflow's timeout duration:
-
Open the invoked workflow.
-
Click Settings in the top-right corner of the canvas.
-
Click the Properties tab.
-
Under Options > Timeout event trigger period, enter the number of seconds after which the workflow will be considered to have timed out.
-
Click Save.
Use the Invoked Workflow's Input Parameters
If the invoked workflow requires that input parameters be provided, those parameters can be used in the same way as regular variables are used. The input parameters are only available within the invoked workflow itself.
An invoked workflow's parameters are listed under Parameters, under the workflow, in the Assests Panel.
In the Cleaning example, the first decision step requires the value of the Shape input parameter.
Set the Return Type of the Invoked Workflow
If the invoked workflow needs to return a value, you must set the type of value that the invoked workflow will return.
The workflow's return type can be modified after it has been configured, even if the workflow's Result or Set Result methods are already in use. See here.
To configure the invoked workflow's return type:
-
Open the invoked workflow.
-
Click Settings in the top-right corner of the canvas.
-
Set the Return Value Type.
-
Click Save.
Set the Value of the Result of the Invoked Workflow
Set the result of the invoked workflow using the Set Result method of the invoked workflow. This method must be included in a step within the invoked workflow and can be included in multiple steps.
In the Cleaning example, the Set Result method would be used in both the Calculate Area of Circle and Calculate Area of Square steps. In the Calculate Area of Square step, Set Result is used to set the result of the calculation to the room's Measurement property multiplied by itself.
Invoke a Workflow
To invoke a workflow, use the invoked workflow's Start method within a step in the invoking workflow.
You can also use the invoked workflow's Start method to invoke a workflow from a Callout or Event handler.
To invoke a workflow:
-
Open the invoking workflow.
-
Click the step at which the invoked workflow must be invoked.
-
In the Assets Panel, open the Workflows section and expand the invoked workflow's tree.
-
Drag the invoked workflow's Start method into the Builder.
-
Specify the invoked workflow's input parameters, if any.
The full process is demonstrated in the video below.
Capture the Response from the Invoked Workflow
If the invoked workflow returns a response, use the invoked workflow's Result method as an input to another function, most commonly the Assign function.
The Result method used to capture the response from the invoked workflow must not be added to the same step as the Start method used to invoke the invoked workflow, as the result will not be ready. See Manage Workflow Timing.
To capture the response from an invoked workflow:
-
Open the invoking workflow.
-
Click the step in which the response will be captured. This step must be later in the workflow than the step at which the invoked workflow is invoked. See Manage Workflow Timing.
-
From the Assets Panel, drag the function or method that will use the invoked workflow's result, such as the Assign function, into the Builder.
-
Click the parameter to be set to the invoked workflow's response and then click to open the Selector window.
-
In the Selector window, expand the Workflows section and expand the invoked workflow.
-
Click the invoked workflow's Result function and click .
The full process is demonstrated in the video below.
Manage Workflow Timing
If the invoking workflow requires a result from the invoked workflow, some time must be allowed for the invoked workflow to run and generate the result. Therefore:
-
In the invoking workflow, the Result method must be included in a step that is later in the workflow than the step that includes the Start method.
-
The transition between the two steps must be made conditional. Use the invoked workflow's Ended condition to pause the invoking workflow until the invoked workflow has ended.
In the Cleaning example, the transition between the step Calculate Room Area and the step Calculate Price for Cleaning must be made conditional on the CalculateArea workflow having ended.
Best Practices
Note the following best practices:
-
The recommended naming convention for input and output parameters of an invoked workflow is lower camelCase, for example, customerName and zipCode.