Subprocedures
Learn how to invoke subprocedures in your automation.
What is a Subprocedure?
In Kognitos, one process can invoke and execute another process. When a process is called by another process within the same execution environment, it is referred to as a subprocedure.
Characteristics
- Subprocedures operate within the same execution environment as the parent process that invokes them.
- When a parent process invokes multiple subprocedures, they will run one after another, in sequence.
- The parent process does not have the ability to implicitly track the subprocedure's output.
How Can I Invoke A Subprocedure?
This section explains how to call a process within another process as a subprocedure.
Syntax
{subprocedure name} with
{inputs}
Input Parameters
subprocedure name
: The name of the subprocedure.inputs
: Any objects or variables the subprocedure needs to run.
Example
In this example, the subprocedure verify applicant qualifications
is invoked with the resume
as input.
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 invoke a subprocedure. This applies to both the main process and the subprocedure.
Returning Data from a Subprocedure
In order to pass a result from the subprocedure back to the main process, you need to add a line into both the parent process and the subprocedure.
In the Subprocedure
At the end of your subprocedure, 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 subprocedure's output. By default, the parent process will only be able to retrieve the subprocedure's 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 Subprocedures
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 invokes the following subprocedures:
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 Subprocedure to Calculate Cake Cost
This example demonstrates how calculate the cost of a cake
is invoked as a subprocedure 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
Subprocedure Inputs
The subprocedure is passed 3 inputs:
the cake quantity
the cake type
the cake pricing
Returning Results from the Subprocedure
The subprocedure 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
Updated 5 days ago