Builders can build calculations and use them across the platform the same way as responses are used, i.e. insert them in documents, notifications, messages and use them when building out rules.
The Variables library shows an overview of all of your bots response and calculation variables. You can also add or edit a calculation from here. The Variables library can be found as a tag in the flowchart, list view, notification page or as a button in the document/web editor Calculation Workspace.
In this article, you'll learn to:
- Create a variable
- Insert a variable into a message, document or notification
- Troubleshoot invalid calculations
- Edit a variable
- Use the variables overview
Create a variable
First, head to either List View or Flowchart. Then click on the Variables library tag, found on the right side of the dashboard.
When you first open up the Variables library, you will see:
- A drop-down field containing a list of existing calculations
- A purple Create calculation button
- An overview of all of your existing response and calculation variables
To build out your first calculation, follow these steps:
1. Click the Create calculation button
A sidebar will appear for you to set out the contents of your variable.
2. Set out the name of your variable in the Variable name field
This is for your reference only, similar to a message name.
3. Set your Calculation result type
Set out the type of result you want your calculation to be:
- Number (a numerical value)
- Date (a formatted date)
- Percentage (a percentage value)
- Currency (a numerical value formatted according to the international currency option you’ve set in your account settings)
- Duration (a period of time set out by number of days, weeks, months or years) The output will be presented as the smallest time unit available e.g. 14 days will be presented as 2 weeks when inserted in documents, notifications or messages.
4. Create your calculation in the Calculation field
Set out the calculation you’d like your bot to perform to build this variable. Make sure the calculation you are building matches the result type you selected in step 3. The mathematical order of operations follows the BODMAS rules.
- Click into the calculation field and insert your response by using the @ key to trigger a list of variables available to you to select from. You may also use the insert variable icon (x) in the toolbar.
- Use standard mathematical operators to add to your calculation. Standard operators such as +, -, /, * can be typed in. Hit space or enter on your keyboard to validate the operator.
- After adding your operator, you may type in numerical values or insert further variables to complete your calculation.
- For calculating dates, you may also select the type duration by typing (e.g. 12) and click into the token to select the duration. You can also type in the number of days, weeks, months, and years (e.g. “1day” or “2weeks”, or “3months”) and confirm with your space/enter key. Please note:
- no space should be included between the number and the time unit
- date calculations include the first day and excludes the last day (e.g. 1 June - 5 June = 4 days)
- 1 week = 7 days
- 1 month = 30 days
- 1 year = 365 days
Once you’ve built out your calculation, click on the Create button to finalise your variable.
Your variable can now be seen in the Variables library workspace.
You may see some of the following messages when adding your calculations. Below is an explanation of what they mean:
It looks like your formula contains invalid characters
- The calculation field contains invalid characters (e.g. duration + #)
It looks like your formula is missing brackets
- Bracket pairs are incomplete (i.e. missing an open or closed bracket)
It looks like your formula is missing an operator, or is incomplete
- The calculation is incomplete (e.g. ends with an operator)
- The calculation has two operators after another (e.g. value + - value)
- The calculation contains values/variables without an operator
Formula is required
- The field is empty
It looks like your formula contains a type combination that isn't allowed
- The variable/value combination is invalid (e.g. date + currency)
- The variable/value and operator combination is invalid (e.g. date * date)
- The variable/value is not allowed (e.g. decimals in durations, such as 1.7 months)
Oh no, your formula isn't matching the result type.
- The calculation isn't matching the result type selected
Insert a variable into a bot message, notification, or generated document
You may insert your variables into bot messages, notifications, and/or generated documents.
To do so, simply locate the insert variable button and follow the prompts:
- In bot messages, the button is in the toolbar in the bottom right of the message text field
- In notifications, the button is in the toolbar in the bottom right of the email content field
- For documents, in the Word and Web editors the button is located in the header at the top
Edit a variable
To edit your variable, simply follow these steps:
- Click on the Variables library sidebar
- Select from the drop-down the variable you’d like to edit, or
- Click on the variable pill in the overview and it will open up the variable for you to edit
To delete a variable, use the red Delete button within the Variables library sidebar and follow the prompts.
Each variable has an overview which tells the builder where in their bot the variable is used. You can find the variables overview when you open the Variables library.