Load arbitrary records into a behavior variable
- Introduction
- Create a bot
- Create a behavior
- Load ticket records as an action
- Use the variable’s records
- Test the behavior
- Conclusion
Introduction
Sometimes your bot behavior needs to act on records that aren’t available as placeholders in the current event.
In these situations, you can use behavior variables to load matching records of any kind from any event.
In this guide, we’ll create an organization behavior that loads a list of the organization’s tickets into a behavior variable.
Create a bot
Let’s create a new bot called Example Bot:
-
Navigate to Search » Bots.
-
Click the (+) icon above the worklist to create a new bot.
- Enter the following details:
- Name:
Example Bot
- Owner: Me
- Name:
-
Click the Save Changes button.
Create a behavior
Now we’ll create a behavior on the new bot:
-
Open the card for Example Bot. You can click the link in the yellow notification above the worklist.
-
Click the Behaviors button.
-
Click the (+) icon above the worklist to create a new behavior.
-
Enter the following details:
- Event: Custom behavior on organization
- Visibility: Private
- Name:
Load organization's tickets
- Status: Enabled
Now let’s add a behavior variable for storing the organization’s ticket records.
-
In the Variables section, click the Add button.
-
Select List » Tickets.
-
In the new List:Tickets entry, set it Private and name it
Tickets
. -
Click the Save Changes button to save the new behavior.
Load ticket records as an action
Finally, we’ll load ticket records into the behavior based on the current organization:
-
Open the card for the Load organization’s tickets behavior. You can click the link in the yellow notification above the worklist.
-
At the bottom of the card, click on Custom behavior on organization and select Add Actions from the menu.
- Enter the following details:
- Title:
Load ticket records for this organization
- Status: Live
- Title:
-
In the Actions section, click the Action button and select Set » (Variable) Tickets from the menu.
- Check the box for and filter using quick search and enter the following query:
org.id:{{org_id}}
-
Click the Save Changes button to save the new action.
List variables can currently hold a maximum of 100 records. You can use loops to process more pages.
Use the variable’s records
The two most common ways to use a variable full of records are:
- Displaying record placeholders in a script
- Running actions on the records
Let’s look at an example of each.
In a script
-
At the bottom of the card, click on Custom behavior on organization and select Add Actions from the menu.
- Enter the following details:
- Title:
Comment a summary on the organization
- Status: Live
- Title:
-
In the Actions section, click the Action button and select Create » Comment from the menu.
-
In the new Create comment action, set Comment on to Organization.
-
In Content, use the following script:
Tickets: {% for ticket in var_tickets %} * [{{ticket.status}}] {{ticket._label}} ({{ticket.created|date_pretty}}) {% endfor %}
-
Click the Save Changes button to save the action.
As a target in actions
-
At the bottom of the card, click on Custom behavior on organization and select Add Actions from the menu.
- Enter the following details:
- Title:
Comment on each ticket
- Status: Live
- Title:
-
In the Actions section, click the Action button and select Create » Comment from the menu.
-
In the new Create comment action, set Comment on to (variable) Tickets.
-
In Content, use the following script:
This ticket was opened by {{org__label}}
-
Click the Save Changes button to save the action.
You can use the Behavior run or Behavior schedule actions to run a Custom behavior on ticket behavior on each ticket record in the list.
Test the behavior
Let’s run the behavior in the simulator:
-
Click the Simulator button at the top of the behavior’s card.
-
Click the magnifying glass button (🔍) at the top of the simulator and select an organization that you know has tickets associated with it.
-
Click the Simulate button.
First, you should see a list of tickets being loaded in the Set (variable) Tickets section. The simulator also gives you instructions for iterating the ticket variable and using its placeholders in scripts.
You can click on the green Set (variable) Tickets heading to hide it.
Next, you should see a comment being created on the target organization with a summary of its tickets. We used placeholders for the status, mask, subject, and created date.
Finally, you’ll see a comment being added on each ticket associated with the organization.
Close the simulator popup.
Conclusion
You now have the incredibly useful ability to load arbitrary records from any behavior.