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
<variable|constant|function> <operator> <variable|constant|function>
In later texts, we alias the above string and its variations with |
lead.values.totalCost / 10
You can expand the expression by applying additional constructs such as addition and division.
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.
{
"username": "testUser",
"email": "test@mail.tld"
}
newUser // results with { "username": "testUser", "email": "test@mail.tld" }
newUser.username // results with "testUser"
newUser["username"] // results with "testUser"
An object selector can use either the |
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
myB = has(myKV, "b") ? myKV.b : "b does not exist"
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"
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. |
[{
"username": "testUser1",
"email": "test+1@mail.tld"
}, {
"username": "testUser2",
"email": "test+2@mail.tld"
}]
newUsers // results with [{ "username": "testUser1", "email": "test+1@mail.tld" }, { "username": "testUser2", "email": "test+2@mail.tld" }]
newUser[0] // results with { "username": "testUser1", "email": "test+1@mail.tld" }
newUser[1] // results with { "username": "testUser2", "email": "test+2@mail.tld" }
newUser[0]["email"] // results with "test+1@mail.tld"
An array selector can only use the |
Operators
|
|
String comparison only:
|
|
|
|
|
|
|
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:
-
d * e
(x1
) -
c + x1
(x2
) -
a + b
(x3
) -
x3 + x2
The execution order may be controlled by enclosing parts of the expression within brackets ()
.