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

Field expressions

Value expressions

Value expressions calculate the fields' value based on the provided expression. A value expression is a simple expression that results in a single value. If your field is a multi-value field, you need to return an array of items.

Refer to the Expressions for details on writing expressions.

Currently, you can only use values of the current record. References are not yet supported. If you need to reference data across multiple records, use automation scripts or workflows instead,

Table 1. Available variables in the evaluation context:

old

The old variable refers to the original record. Only set when the field is being updated.

new

The new variable refers to the current record.

<field-name>

A string or an array of strings with current field values. If the field name collides with any of the system-defined variables, access the value via the new["field_name_here"].

Example expression that calculates the price with tax:
price * 1.25
Example expression that generates a full name:
trim(firstName + " " + lastName)
Example of a multi-value expression evaluation:
["foo", "bar", "baz"]

Sanitizers

Sanitisers modify the field value to cleanup (sanitise) the data before it is saved. A sanitiser is a simple expression that results in a single value.

Refer to the Expressions for details on writing expressions.

By their nature, sanitisers should not result in an error. If an error occurs, it is logged in the action log, and the operation continues.

If you define multiple sanitisers, they are run in the specified order.

Example sanitiser that limits the text length:
length(value) > 5 ? substr(value, 0, 5) + "..." : value
Table 2. Available variables in the evaluation context:

value

The value variable refers to the current value.

Validators

Validators validate the field value by raising errors when the value is not valid. A validator is a simple expression that results in a single value, either true or false. The value validation is considered invalid when the expression results in true.

Validators can not change the value.

Built-in field validators can be disabled; required and unique-multi-value validators can not be disabled.

If you define multiple validators, they are run in the specified order.

The field validator stops when the first error occurs. For example, if we define validators A, B, and C, and the validator A raises an error, validators B and C are not evaluated.

Validation expressions are not executed when:
  • the value is not changed,

  • the value is missing.

Use the required flag to check for required values.

Table 3. Available variables in the evaluation context:

value

The value variable refers to the current value.

oldValue

The oldValue variable refers to the original value. Only set when the field is being updated.

values

The values variable refers to all record values (values.<field-name>). You can use this to write validators that are context-aware.

Example validator to check the text length:
length(title) < 5