Expressions

Calculate, compare and format with the expression editor. Data and expressions in the DocStudio designer user guide.

An expression is a small calculation. It is built with the expression editor, never typed as code, and it can never run scripts.

The editor

Wherever a value can be computed you see an expression editor. Choose its kind:

Kind Use
Fixed value A text, number, true or false, or empty
Data path A value from the data, with an optional fallback
Function A calculation with arguments

Below the editor a preview shows the value, its type and the binding state, evaluated with your sample data. Use Edit as JSON to see or paste the raw expression.

Functions

Group Functions
Arithmetic add, sub, mul, div, mod, round, abs, number
Comparison eq, ne, gt, gte, lt, lte
Logic and, or, not, if, coalesce
Presence exists, isEmpty, contains, in
Text concat, upper, lower, trim, length, substr
Aggregates sum, avg, count, min, max
Formatting format

Rules to remember:

  • Numbers are never converted from text automatically. Use number to convert a decimal text.
  • round rounds half away from zero: 1.005 rounds to 1.01 with 2 digits.
  • if(condition, then, else) evaluates only the branch it needs.
  • Errors never stop the document: a bad calculation gives an empty value and a warning in Problems.

Examples

Goal Expression
Line total mul(qty, price)
Order total sum over items with the per item part mul(qty, price)
Full name concat(first, " ", last)
Money format("currency", total, "USD")
Late flag gt(daysOverdue, 30)

Aggregates

sum, avg, count, min and max work on a list. The per item part is an expression evaluated for every item. A sum of mul(qty, price) over items adds the line totals.

Wrap in a function

Select any expression and use Wrap in function to put it inside another function, for example to uppercase a path. Remove function unwraps it again.

Limits

An expression can have up to 64 arguments per call and a limited depth and size. The function set is closed: you cannot add your own functions in the editor.

Full language reference: Expressions.