Calling A Subprocess
Learn how to call a subprocess in your automation.
Introduction
In Kognitos, a parent process can call another process using the invoke
keyword. The called process is referred to as a subprocess. Subprocesses run in the same execution environment as the parent process. If a parent process invokes multiple instances of a subprocess, they will execute sequentially, one after the other.
Parent Process
│
Subprocess
│
Subprocess
│
Subprocess
How Can I Call A Subprocess?
This section explains how to call a process within another process as a subprocess using the invoke
keyword.
Syntax
invoke {subprocess name} with
{inputs}
Input Parameters
subprocess name
: The name of the subprocess.inputs
: Any objects or variables the subprocess needs to run.
Example
In this example, the subprocess verify applicant qualifications
is called with the resume
as input.
invoke verify applicant qualifications with
the resume
Remember to Publish Your Process
You need to promote your automation from the Playground to a Process in order to call a subprocess. This applies to both the main process and the subprocess.
Returning Data from a Subprocess
In order to pass a result from the subprocess back to the main process, you need to add a line into both the parent process and the subprocess.
In the Subprocess
At the end of your subprocess, include one of the following lines:
- For a single result:
the result is {result}
- For multiple results:
the results are {result 1}, {result 2}, {result 3}, ...
If the results are not explicitly defined in this format, the parent process will not be able to access the subprocess output. By default, the parent process will only be able to retrieve the subprocess' status.
In the Parent Process
In the parent process, retrieve those results using get the answer
or get the answers
.
Example: Bakery Order Processing With Subprocesses
Consider an automation for processing a custom bakery order.
The main process, process a bakery order
, determines the total cost of a customer's order. It calls the following subprocesses:
calculate the cost of a cake
: Calculates the cost for a cake in the order.calculate the cost of the cookies
: Calculates the cost for cookies in the order.calculate the cost of the cupcakes
: Calculates the cost for cupcakes in the order.calculate the sales tax
: Calculates the applicable sales tax.summarize the grand total
: Summarizes the final total for the order.
Invoking A Subprocess to Calculate Cake Cost
This example demonstrates how calculate the cost of a cake
is called as a subprocess within the main process, process a bakery order
.
calculate the cost of a cake with
the cake quantity
the cake type
the cake pricing
get the answer as the cake total
Subprocess Inputs
The subprocess is passed 3 inputs:
the cake quantity
the cake type
the cake pricing
Returning Results from the Subprocess
The subprocess will perform some calculations for the cake cost
and return it at the end using the result is the cake cost
.
.
.
the cake cost is the cake price * the cake quantity
the result is the cake cost
Getting Results in the Parent Process
The total price of the cake is retrieved in the main parent process using get the answer
. This line retrieves the result (cake cost
) and renames in the parent process as total cake cost
.
get the answer as the total cake cost
Video Walkthroughs
1. Invoke a Process
This video shows how to invoke a process as a subprocess.
2. Using A Subprocess
This video demonstrates how to incorporate subprocesses within larger workflows.
Updated about 2 months ago