Expressions
Expressions allow you to manipulate, format, and parameterize data throughout SquaredUp using Mustache-style placeholders {{ }} combined with JavaScript.
While expressions all use the same syntax, they serve different use cases depending on the area of SquaredUp you’re configuring.
Where expressions can be used
There are several main areas in SquaredUp that allow you to use expressions:
- Columns
Use expressions to alter how values are displayed. - Custom columns
Use expressions to create new values by manipulating existing data, and optionally format how those - Data stream parameters
Use expressions to parameterize requests with dynamic values such as timeframes and variables.
Expressions in columns
When editing a column, you can use format expressions to manipulate how a value is displayed on screen.
This is purely cosmetic and the actual value remains unchanged, meaning that any sorting or aggregation you perform on that column will still use that original value.
Examples
Perform calculations on values
{{ $['myColumn'] / 1000 }}Combine text and/or multiple columns
Progress: {{ $['myColumn'] }} out of {{ $['myColumnTwo'] }}Manipulate a string to remove/replace part of it
{{ $['myColumn'].substring(0, 20) }}Expressions in custom columns
When creating a custom column, you can use value expressions to create completely new values by manipulating the available data.
Value expressions are used to define the actual value of the column. You can then apply a format expression to control how that value is displayed.
Examples
Create URL columns
https://example.com?ticketId={{ $['id'] }}Map values to create state or boolean columns
{{ $['value'] / 100 ? 'success' : 'error' }}
{{ $['log'].includes('ERROR') }}Expressions in data stream parameters
When configuring a data stream on the Parameters tab of the tile editor, you can use implement dynamic configuration by injecting variables (such as timeframes or user-defined values) directly into fields.
These parameter expressions allows a single configuration to adapt automatically based on context, rather than relying on hard-coded values. Fields which allow parameter expressions are denoted by the Insert expression
button.Clicking Insert expression
opens the expression picker, where you can quickly insert common expressions. For example,{{timeframe}}, {{variable1}}, etc.Writing expressions
Expressions uses Mustache-style placeholders ({{ }}) that contain JavaScript. Within a placeholder, you can use JavaScript to access the current row of data as well as other variables like the array of all rows, or current index.
A single expression may contain multiple placeholders as well as literal text. For example:
Progress: {{ $['myColumn'] }} out of {{ $['myColumnTwo'] }}
This would display:
Progress: 10 out of 20.
Accessing data
You can access data and context using the following variables:
IntelliSense
The editor used for inputting an expression provides IntelliSense support, making suggestions and showing which commands / properties are available. IntelliSense is automatically triggered as you type, or can be manually triggered using Ctrl+Space.
Error handling and troubleshooting
If a placeholder throws an error or contains invalid JavaScript syntax, the error message is captured and used as the output of the placeholder for debugging purposes.
How to use expressions with columns
- From the tile editor, select the Columns tab.
- Click on the column you want to format. The Configure column window opens.
- Configure the following fields:
- Name:
Enter a name for the column. - Type:
Select the data type of the column. Depending on the data type you select this enables additional configuration fields.
- Name:
- Value expression:
Only displays when editing a custom column. Enter your custom expression to manipulate the actual value of the column. - Select Custom from the Formatting section.
- Format Expression:
Enter your custom expression to cosmetically change how the value displays.The configure column window accessed via a custom column