Expressions

With this feature, you can define a dynamic value for a block based on the data from:

GoLess uses a mustache templating model and expands it with data from overhead and functions.

Writing Expression

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:

{{variables.socials}}

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:

{{variables.socials.0.url}}

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.

Access Another Data Inside the Expressions

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:

{{$increment([variables.variableName]}}

{{table.[loopData.loopId.$index].columnName}}

Functions

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

$date("DD MMMM YYYY") // 14 January 2022
$date("DD-MM-YYYY, hh:mm A")  // 14-01-2022, 02:24 PM
$date("relative") // A few seconds ago
$date("timestamp") // 1651118110948

$date("2005-06-07", "DD MMMM YYYY") // 07 June 2005
$date("1977-04-01T14:00:30", "DD-MM-YYYY, hh:mm A")  // 01-04-1977, 02:00 PM
$date("14 January 2021", "relative") // A year ago
$date("14 January 2021", "timestamp") // 1610553600000

$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

$randint() // 30
$randint() // 14

$randint(0, 10) // 4
$randint(0, 10) // 7

$getLength(str)

Gets the length of an array or string.

Examples

// Get the length of a string
$getLength("testing") // 7

// Get tabel length
$getLength([table]) // 14

// Get the length of the "text" column on the second row
$getLength([table.1.text]) // 5

$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

$randData("?d?d") // 89

$randData("[email protected]") // [email protected]

$randData("?d?u?s?l?l?s?a?m") // 4C%ee^MF9

$multiply(value, multiplyBy)

Multiplies a value.

Examples

$multiply(5, 2) // 10

// Multiply a variable
$multiply([variables.variableName], 0.3) //20.7

$increment(value, incrementBy)

Increments a value.

Examples

$increment(10, 2) // 12

$increment(72, 2) // 74

$divide(value, incrementBy)

Divides a value.

Examples

$divide(22, 7) // 3.142857142857143

$divide(10, 2) // 5

$subtract(value, incrementBy)

Subtracts a value.

Examples

$subtract(80, 7) // 73

$subtract(11, 2) // 9

$replace(value, search, replace)

Replaces a search string from value with a replace string.

Examples

$replace("hello world!", "world", "everyone") // hello everyone!

$replace("hello world!", "hello", "hi") // hi world!

$replaceAll(value, search, replace)

Replaces all the matches string search from value with a replace string.

Examples

$replace("hello world!", "o", "0") // hell0 w0rld

$replace("The temperature is 25 degrees today", " ", "") // Thetemperatureis25degreestoday

$toLowerCase(value)

Converts value to a lowercase

Examples

$toLowerCase("HELLO WORLD!") // hello world!

$toLowerCase("hELLO wORLD!") // hello world!

$toUpperCase(value)

Converts value to a uppercase

Examples

$toUpperCase("hello world!") // HELLO WORLD!

$toUpperCase("hELLO wORLD!") // HELLO WORLD!

$modulo(num, divisor)

Returns the remainder or signed remainder of a division.

Examples

$modulo(13, 5) // 3

$modulo(-13, 5) // -3

$modulo(4, 2) // 0

$modulo(-4, 2) // -0

$filter(data, syntax)

Filter/Query javascript object. GoLess uses the JSONPath library to make a query.

Examples

Querying colors variable with these as the value:

[
	{ color: "red", value: "#f00" },
	{ color: "green", value: "#0f0" },
	{ color: "blue", value: "#00f" },
	{ color: "cyan", value: "#0ff" },
	{ color: "magenta", value: "#f0f" },
	{ color: "yellow", value: "#ff0" },
	{ color: "black", value: "#000" }
]
{{ $filter([variables.colors], "$..color") }}
// ['red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'black']

{{ $filter([variables.colors], "$..value") }}
// ['#f00', '#0f0', '#00f', '#0ff', '#f0f', '#ff0', '#000']

Using JS Expressions

!!{{ $filter(variables.colors, "$..color") }}
// ['red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'black']

!!{{ $filter(variables.colors, "$..value") }}
// ['#f00', '#0f0', '#00f', '#0ff', '#f0f', '#ff0', '#000']

$stringify(value)

Converts JavaScript value to a JSON string.

Examples

This section gives further examples of writing expressions and provides some information about the structure of the source data.

Table

The table is stored as an array of objects with the table column as the object key.

[
  { "color": "blue", "value": "#00f" },
  { "color": "cyan", "value": "#0ff" },
  { "color": "magenta", "value": "#f0f" },
  { "color": "yellow", "value": "#ff0" },
  { "color": "black", "value": "#000" }
]
  • 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

Variables

The variables are stored as an object with the variable title as the object key.

{
  "url": "https://goless.com",
  "numbers": [100, 500, 300, 200, 400]
}
  • 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

JavaScript Expressions

::: 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:

{{$getLength(table)}} //10

{{$randData("?d?d")}} // 89
  • Get the last row of the table:

{{table[table.length - 1].columnName}}
  • Get current timestamp:

{{Date.now()}} //1666237704022
  • Access loop data and index:

// Loop data
{{loopData.loopId.data}}

// Loop index
{{loopData.loopId.$index}}

Last updated