Example of passing a value between bots
Learn how to pass a value from one TaskBot to another by using a dictionary variable.
To pass values between TaskBots, use any variable type in the child bot and a dictionary variable in the parent bot. This example uses a string variable called sMySong in the child bot.
Procedure
-
Build the child bot with the following steps:
-
On the left panel, click Automation.
A list of available bots and forms is displayed.
- Click Create New > Bot.
- Enter the name for the bot as FavoriteSongs
- Enter the folder location as Bots\TaskBotExample.
- Click Create and Edit.
-
On the left panel, click Automation.
-
Create the variable:
sMySong
and select both check-boxes: use as input and use as output for this variable. -
Use the Prompt > For value
action to capture a song name.
- Find the action Prompt > for value and double-click or drag the action into your flow.
- In the Prompt window caption field, enter Add a song.
- In the Prompt message field, enter Type in a favorite song.
-
In the Assign the value to a variable field,
enter sMySong.
Note: In the List display mode, your child bot should be one line of code:
Prompt: For value
- Click Save and then click Close.
-
Build the parent bot with the following steps:
- From the Control Room interface, select Bots > My bots.
- Click Create New > Bot.
- Enter the name for the bot as GetFavoriteSongs.
- Enter the folder location as Bots\TaskBotExample.
- Click Create and Edit.
-
Create the following two variables:
sMySong
: select string as the subtypesPassedSong
: select dictionary as the type and string as the subtype
-
Use the Task Bot > Run
action to call the child bot:
- Find the action Task Bot > Run and double-click or drag the action into your flow.
- In the Task Bot to run field, select Control Room and click Choose.
- Click Browse, navigate to Bots\TaskBotExample, and select FavoriteSongs.
- In the section Input values, select Set sMySong.
- In the Save the outcome to a variable (option), select Dictionary, and then select sPassedSong.
- Click Save.
-
Use the action
Dictionary > Get to accept the value returned from the child bot.
- Find the action Dictionary > Get and double-click or drag the action into your flow.
- In the Dictionary Variable field, select sPassedSong.
- In the Key field, select sMySong.
- In the Assign the output to variable field, select sMySong.
- Click Save.
-
Use a Message box
action to report what was returned from the child bot:
- Find the action Message box and double-click or drag the action into your flow.
- In the field Enter the message box window title, enter What do you like?.
- In the Enter the message to display field, enter You said, $sMySong$.
-
Click Save.
Note: In List display mode, your parent bot should look like this:
Start Task Bot: Run and assign output to variable Dictionary: Get value of the key "sMySong" from SsPassedSongS Message box "You said, $sMySong$" End
-
Click Run to deploy your bot.
When prompted to Set input variables, click Confirm. Follow the prompts and a message box should return the same value you entered for your song. If no value is returned, ensure you have performed the steps to assign the incoming value to a dictionary key and a variable.