Expressions

Expressions

Template allows you to use expression language to define variables and operations on them. This way you can derive new values and reduce necessary input either from user or external system.

Elements

  • 123 - Number
  • "Peter" - Constant string
  • Name - Variable
  • + - Operator
  • ABS(X) - Function

Numbers

Numbers and operations with them are handled with highest precision. Acceptable number format is simple: 123.456 - starting with digits, followed by decimal separator and ending with digits again. Decimal part is not mandatory.

Variables

A simple word defines a variable name. It consists of upper or lower case letters and can contain, but cannot start with underscore character.

Valid examples:
Name
email
UnitPrice
order_number

You can define or refer to a variable within an object using dot notation, where . connects object and variable name. Example:
Address.City

Operators

  • + - addition
  • - - subtraction
  • * - multiplication
  • / - division
  • % - modulo
  • > - greater than
  • >= - greater than or equal to
  • < - lower than
  • <= - lower than or equal to
  • = - assignment
  • == - equal
  • != or <> - not equal

Functions

  • NOT(A) - logical negation
  • AND(A, B, ...) - logical AND
  • OR(A, B, ...) - logical OR
  • IF(C, A, B) - if logical condition C is true, result is A, otherwise B
  • ABS(A) - absolute value of number A
  • MAX(A, B, ...) - maximum value of values A, B, ...
  • MIN(A, B, ...) - minimum value of values A, B, ...
  • SIZE(V) - size of vector V
  • SUM(V, X) - sum of expression X on vector V
  • SUMC(V, X, F, T) - conditional sum of expression X on vector V, where expression F has target value T
  • NUM(N, D) - print number N with D digits, pad with leading zeroes
  • NUM(N, D, P) - print number N with D digits and P decimal places, pad with leading and trailing zeroes
  • ROUND(D, S) - round decimal number D with S scale, rounding half up
  • REPLACE(A, B, C) - replace string B with string C in A expression
  • DATE(D, F) - print date D in F format (y, M, d, H, m, s)
  • TO_DATE(A, F) - parse string A to date using format F (y, M, d, H, m, s)
  • DAYS(D) - convert number of days D to date

Types

Variable types can be boolean, number, string, date, or vector. Default type is string, but other types are inferred based on operations or functions used. For example, A + 3 sets A to number type, which helps eliminate input errors by forcing number input.

If conflicting types arise, e.g. A + 3 (number) and A + ".pdf" (string), the more format-strict type (number) will be used.


Was this article helpful?

Yes

No