You are reading the documentation for an outdated Corteza release. 2024.9 is the latest stable Corteza release.

Expressions

Corteza defines an expression language which is used when defining field expressions, workflow steps, as well as contextual roles.

We use Gval as the expression evaluation engine. Refer to the official documentation for technical details.

Syntax

The most basic form of an expression would follow the following pattern:
<variable|constant|function> <operator> <variable|constant|function>

In later texts, we alias the above string and its variations with expression.

To examplify:
lead.values.totalCost / 10

You can expand the expression by applying additional constructs such as addition and division.

To examplify:
average(min(lead.values.a, lead.values.b), abs(lead.values.c))

Variables

The expression engine does not allow you to define custom variables within the expression itself. All variables are defined by the system in which the expression is being executed.

The available variables are either documented in the system’s user interface or in dedicated documentation pages.

Objects

Objects allow you to encapsulate different bits of information into a single variable, such as a user, role, or record.

The primitive object-like data types include KV and KVV; other component defined object-like data types can be found here.

In the simplest form, an object is defined as the below example shows:
{
  "username": "testUser",
  "email": "test@mail.tld"
}
If you would like to reference the entire object, you should reference the variable; for example:
newUser // results with { "username": "testUser", "email": "test@mail.tld" }
If you would like to reference specific properties of the object, you should use a selector; for example:
newUser.username // results with "testUser"
newUser["username"] // results with "testUser"

An object selector can use either the ["<selector>"] or the .<selector> notation.

Missing Properties

Accessing missing (non-existing) properties results in an error:

myKV = { "a": "value-of-a" }
myB = myKV.b // throws an error: unknown parameter myKV.b
Use the ternay operator to make a simple one-line test expression.
myB = has(myKV, "b") ? myKV.b : "b does not exist"
Deeper structures can also be checked in a similar way.
deepKV = { "a": { "b": 42 } }
myB = has(deepKV, "a") && has(deepKV.a, "b") ? deepKV.a.b : "a.b does not exist"

Missing Record Values

Record values can be accessed in the same way as object and other key-value types. The underlying selector mechanism on record values performs extra checks and allows selection (reading) of unset values as long as the module field exists.

// Accessing defined fields on a record
hit1 = myRecord.values.existingFieldWithValueSet
hit2 = myRecord.values.existingFieldWithoutAValue

// Accessing undefined fields on a record
miss = myRecord.values.unknownField // will raise an error: "unknown parameter myRecord.values.unknownField"
Use the null coalescing operator to make a simple one-line test expression for unset fields.
failsafe = myRecord.values.existingFieldWithoutAValue ?? 'value was not yet set'

Arrays

Arrays allow you to encapsulate a series of values into a single variable such as a list of leads or contacts you would like to create.

Array is the only native array data type. An array can contain any data type, including another array.

Nested arrays allow you to define a multidimensional matrix.

In the simplest form, an array is defined as the below example shows:
[{
  "username": "testUser1",
  "email": "test+1@mail.tld"
}, {
  "username": "testUser2",
  "email": "test+2@mail.tld"
}]
If you would like to reference the entire array, you should reference the variable; for example:
newUsers // results with [{ "username": "testUser1", "email": "test+1@mail.tld" }, { "username": "testUser2", "email": "test+2@mail.tld" }]
If you would like to reference specific elements of the array, you should use a selector; for example:
newUser[0] // results with { "username": "testUser1", "email": "test+1@mail.tld" }
newUser[1] // results with { "username": "testUser2", "email": "test+2@mail.tld" }
If you wanted to access a property of the object that is inside an array, you should add an object selector:
newUser[0]["email"] // results with "test+1@mail.tld"

An array selector can only use the [] notation.

Operators

Arithmetic

  • + (addition)

  • - (subtraction)

  • * (multiplication)

  • ** (power of)

  • / (division)

  • % (modulo)

Comparison

  • < (less then)

  • (less or equal then)

  • > (greater then)

  • >= (greater or equal then)

  • == (equal)

  • != (not equal)

String comparison only:
  • =~ (equal regular expression)

  • !~ (not equal regular expression)

Boolean algebra

  • && (and)

  • || (or)

  • ! (not)

Bit operations

  • << (shift)

  • >> (un shift)

  • & (bitwise and)

  • | (bitwise or)

Ternary conditional

  • ?: (ternary: a?b:c if-a-then-b-else-c)

  • ?? (null coalescing operator: a??b if-a-is-not-null-then-a-else-b)

Order of Execution

Expressions follow "the usual order" of execution where the order is initially based on operator precedence where the operators with equal precedence are executed left to right.

To exemplify; the order of execution for the expression of a + b + (c + d * e) would be:

  1. d * e (x1)

  2. c + x1 (x2)

  3. a + b (x3)

  4. x3 + x2

The execution order may be controlled by enclosing parts of the expression within brackets ().

Operator Precedence

0

Left to right

  • ()

  • []

  • .

1 (unary)

Right to left

  • +

  • -

  • !

2

Left to right

  • *

  • **

  • /

  • %

3

Left to right

  • +

  • -

4

Left to right

  • <<

  • >>

5

Left to right

  • <

  • >

  • >=

6

Left to right

  • ==

  • !=

  • =~

  • !~

7

Left to right

  • &

8

Left to right

  • |

9

Left to right

  • &&

10

Left to right

  • ||