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 called sMySong in the child bot.
Procedimiento
Build the child bot.
-
Create a bot:
-
On the left panel, click Automation.
A list of available bots and forms is displayed.
- Click Create New > Bot.
- Provide a name for the bot: FavoriteSongs
- Enter the folder location: Bots\TaskBotExample
- Click Create and Edit.
-
On the left panel, click Automation.
-
Create a variable:
sMySong
: string type; use as input, use as output. -
Use a Prompt > For value
action to capture a song name.
- Double-click or drag the Prompt > for value action.
- 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.
Nota: 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.
-
Create a bot:
- From the Control Room interface, select Bots > My bots.
- Click Create New > Bot.
- Provide a name for the bot: GetFavoriteSongs
- Enter the folder location: Bots\TaskBotExample.
- Click Create and Edit.
-
Create the following variables:
sMySong
: string typesPassedSong
: dictionary type/string subtype
-
Use a Task Bot > Run
action to call the child bot:
- Double-click or drag the Task Bot > Run action.
- In the Task Bot to run field, select Control Room and click Choose.
- Click Browse, navigate to Bots\TaskBotExample, and select FavoriteSongs.
- In Input values, select Set sMySong.
- In Save the outcome to a variable (optional), select Dictionary, and then select sPassedSong.
- Click Save.
-
Use the Dictionary > Get
action to accept the value returned from the child bot.
- Double-click or drag the Dictionary > Get action.
- 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:
- Double-click or drag the Message box action.
- In the Enter the message box window title field, enter What do you like?.
- In the Enter the message to display field, enter You said, $sMySong$.
-
Click Save.
Nota: 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
-
Run 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.