Expressions
Last updated
Last updated
With this feature, you can define a dynamic value for a block based on the data from:
Title | Description | Access item |
---|---|---|
GoLess uses a mustache templating model and expands it with data from overhead and functions.
To write an expression, you should use the following format: "{{ keyword }}
". Change the keyword
with one of the data sources mentioned above. It helps GoLess distinguish static from dynamic data.
For example, assume that you have a variable named socials
inside the workflow. Its value is an array of objects. You can use the HTTP Request block to send this variable to the API.
The following phrase can be used in the body of the HTTP Request block:
If you want to use the url
property on the first element of the array as a value inside the New Tab block URL, you can use the following expression:
The first element of the array here is expressed as 0
. Use 1
for the 2nd element of the array, 2
for the 3rd element, 3
for the 4th element, etc.
Wrap the expression with a bracket ([]
) to access other data inside the expression. For instance, let's take the situation when you want to increment a variable using the $increment
function or get the table row based on the current index of the loop. In this case, you can write the expressions as follows:
All built-in functions always begin with the prefix $
, for instance, $funcName(param)
; here is a reference list of available functions in GoLess.
$date(date, dateFormat?)
This fuction gets or formats a date. It takes two parameters, the second parameter is optional.
Suppose you want to format the current date. In that case, you can pass the dateFormat
straight as the first parameter. For example,{{ $date('DD-MMMM-YYYY') }}
, and the output would be 14-January-2022. You can check all the available date formats on the day.js page.
Also, you can check the valid date format on the MDN page for the date
parameter.
Examples
$randint(min?, max?)
Produces a random number. You can set up the range of the random number by entering the min
and max
parameters.
Examples
$getLength(str)
Gets the length of an array or string.
Examples
$randData(expression)
This function generates random data. Pass an expression to its parameter and it will generate something random. For instance, $randData("?l")
will produce a random minuscule letter like a
. Supported expressions:
?l
: lowercase
?u
: uppercase
?d
: number
?f
: uppercase + lowercase
?s
: symbol
?m
: uppercase + number
?n
: lowercase + number
?a
: any
You can also mix several expressions together. For example, $randData("[email protected]")
will produce [email protected]
.
Examples
$multiply(value, multiplyBy)
Multiplies a value.
Examples
$increment(value, incrementBy)
Increments a value.
Examples
$divide(value, incrementBy)
Divides a value.
Examples
$subtract(value, incrementBy)
Subtracts a value.
Examples
$replace(value, search, replace)
Replaces a search
string from value
with a replace
string.
Examples
$replaceAll(value, search, replace)
Replaces all the matches string search
from value
with a replace
string.
Examples
$toLowerCase(value)
Converts value to a lowercase
Examples
$toUpperCase(value)
Converts value to a uppercase
Examples
$modulo(num, divisor)
Returns the remainder or signed remainder of a division.
Examples
$filter(data, syntax)
Filter/Query javascript object. GoLess uses the JSONPath library to make a query.
data
: Javascript object to query
syntax
: JSONPath Syntax
Examples
Querying colors
variable with these as the value:
Using JS Expressions
$stringify(value)
Converts JavaScript value to a JSON string.
This section gives further examples of writing expressions and provides some information about the structure of the source data.
The table is stored as an array of objects with the table column as the object key.
Get the first row:
expression: {{ table.0 }}
output: { "color": "blue", "value": "#00f" }
Get the second row:
expression: {{ table.1 }}
output: { "color": "cyan", "value": "#0ff" }
Get the last row:
expression: {{ table.$last }}
output: { "color": "black", "value": "#000" }
Get value of the color
column on the first row:
expression: {{ table.0.color }}
output: blue
Get value of the value
column on the first row:
expression: {{ table.0.value }}
output: #00f
The variables are stored as an object with the variable title as the object key.
Get the value of the url
variable:
expression: {{ variables.url }}
output: https://goless.com
Get the value of the numbers
variable:
expression: {{ variables.numbers }}
output: [100, 500, 300, 200, 400]
Get the first number of the numbers
variable:
expression: {{ variables.numbers.0 }}
output: 100
::: Note: this is only supported in the browsers based on Google Chromium :::
With GoLess, you also use javascript within the expressions. To write a javascript, you must add !!
symbols as the first value on a text field of a block. For instance, from The number is: {{variables.number}}
to!!The number is: {{variables.number}}
.
You can also use the integrated function like the javascript function.
Examples
Use of integrated functionality:
Get the last row of the table:
Get current timestamp:
Access loop data and index:
table
Retrive data from the Table
table
variables
Retrive data from the Variables
variables.<variableName>
loopData
Retrive the current iteration data of the Loop Data block
loopData.<loopId>
prevBlockData
Retrive the data of the previous block
prevBlockData
globalData
Retrive the global data of the workflow
globalData
googleSheets
Retrive the Google Sheets data
googleSheets.<referenceKey>
activeTabUrl
Retrive the active tab url
activeTabUrl
workflow
Retrive the data (Table and Variables) of the workflow that have been run by the Execute Workflow block
workflow.<executeId>