The Run
action from the Task Bot
package enables you to run and pass values to one or more child bots. In this example, you use the Run
action to pass two values from a parent bot to the child bot; the child bot adds the values and passes the sum back to
the parent bot.
This example demonstrates the following:
- Modularization
- Modularization separates a Task Bot into several bots, where each bot is built with all the actions necessary to perform one specific function of the
greater task.
- In this example, you build a single child bot to add the
values. You can build several child bots, with each
performing a different mathematical operation, and edit the parent bot to call whichever one you want to use.
- Reusability
- Reusability enables the user to build a bot once, and then
use that bot to automate many processes.
- The child bot contains only the actions
necessary to add the values and print them to a Message Box. Also, the bot adds two
variables instead of hard-coded values. As a result, this bot
can be reused for any task that involves an addition operation.
- Data control
- Because the child bot accepts and returns values only through
the use of variables, it does not hold data. This minimizes the chance of
data leakage.
Procedure
To run a Task Bot from the current task, perform these
steps:
Build the child bot.
-
Open a new bot.
-
On the left panel, click Automation.
A list of available bots and forms is displayed.
-
Click Create a bot.
-
Enter the bot name
AddChildBot.
-
Enter the folder location Bots\TaskBotExample.
To change where your bot is stored, click
Choose and follow the prompts.
-
Click Create and Edit.
-
Create the following variables:
-
v1
: number type; use as input
-
v2
: number type; use as input
-
nSum
: number type
-
sSum
: string type; use as output
-
Use a
action to perform the mathematical operation.
-
Double-click or drag the
action.
-
In the Select the source string variable/ value
field, enter the following expression: $v1$ +
$v2$
-
Select
nSum
from the Select destination
number variable list.
-
Use the
action to convert the value so it can be printed to a Message Box.
-
Double-click or drag the
action.
-
In the Enter a number field, enter the following
expression: $nSum$
-
Select
sSum
from the Assign output to
variable list.
-
Click Save.
-
Click Close.
Build the parent bot.
-
Open a new bot.
-
On the left panel, click Automation
A list of available bots and forms is displayed.
-
Click Create a bot.
-
Enter the bot name MathBot.
-
Enter the folder location \Bots\TaskBotExample.
To change where your bot is stored, click
Choose and follow the prompts.
-
Click Create and Edit.
-
Create a Dictionary variable of Any subtype named
dSums
to
accept the values passed from the child bot.
Use the Any subtype to enable the parent bot to accept String,
Number, or Boolean type values.
-
Insert a
action to specify the values for the mathematical operation and
the output variable to hold the sum.
-
Double-click or drag the
action.
-
Click Browse to navigate to
Bots\TaskBotExample\AddChildBot.
-
Enter the following values in the Input values
fields:
-
Select
dSums
from the Assign output to
variable list.
Note:
Use a Dictionary variable to hold the
output of the Run
action in order to make the parent bot more versatile. This way a parent bot can handle different child bots regardless of whether they return a single value or several
values.
-
Use a Message Box to retrieve and print the sum.
The variable sSum
retrieved from the child bot
is a key in the Dictionary variable dSums
.
Note:
You
must know the variable names from the child bot to
extract them from the parent bot. The interface does
not automatically import the variable names to the parent bot.
-
Double-click or drag the Message box
action.
-
Enter $dSums{sSum}$ in the Message to
display field.
-
Click Save.
-
Click Run.
The bot runs and the Message Box appears
containing the sum 66.