Expression

This content applies to legacy design tools (such as K2 Studio, K2 for Visual Studio, or the Silverlight-based K2 workflow design tool). If you have upgraded from K2 blackpearl 4.7 to K2 Five, these tools may still be available in your environment. These legacy tools may not be available in new installations of K2 Five. These legacy tools may also not be available, supported, or behave as described, in future updates or versions of K2. Please see the legacy component support policy for more information about support for these components.

An expression can be a short expression that refers to a field object or a long expression that supports decision functions or formatting based on fields or other items.

A function is selected and then added to the canvas or K2 field part by clicking the Add button or by dragging it to the right place. After adding the function, the wizard for the specific function displays.

Category Functions Description
Expression Build Expression The Build Expression wizard enables you to build expressions that perform operations and return values.

The Expression Wizard is opened from either selecting the Expression function from the Context Browser > Function Browser or by clicking on the button on a Function Wizard page.

The expression builder includes a set of operators and functions for use in the Expression Wizard. An expression can use a single function but typically it combines functions with operators and uses multiple functions.

Important: List data types cannot be used in expressions. Examples of list data types are binary data fields, XML repeating sections, SmartObject lists and functions returning arrays or binary (array of bytes).

The following functions cannot be used in the expression builder:

Feature Function
Conversion

To Binary - Return type: array of bytes.

To Bytes - Return type: array of bytes.

InfoPath Get Attachment Content - Return type: array of bytes.
Text
Split - Return type: array of strings.

An operator is added by clicking on the specific operator button or by typing it in directly. Parenthesis can also be added by clicking on the paren-ellipses (...) button.

To distinguish between Text and Numeric values, quotes (single or double) are used for text.
For example:
When using & for joining text strings, “abc” & “def” results in “abcdef”
When using + for adding numeric values, 1.0 + 2.0 results in 3.0

The supported operators are categorized as follows:

Category Operators Description
Mathematical =, <, >, +, -, *, /, ^ , <=, >=

equal, less than, greater than, plus, minus, multiply, divide, power of, less than or equal to, greater than or equal to

Text & Concatenates strings (including static values such as "<space>") together
Logical =, <>, And, Or, Xor equal, not equal, and, or, xor
Date and Time =, <, >, <=, >= equal, less than, greater than, less than or equal to, greater than or equal to

BODMAS

The expression builder adheres to BODMAS (Brackets, Over, Divide, Multiply, Add, Subtract) rules.

Expressions are evaluated in the following order:

  • Brackets
  • Boolean (and, or, xor)
  • Comparison (<, >, <=, >=, <>, =)
  • Multiply, Divide, Mod, Power (*, /, mod, pow)
  • Addition, Subtraction, Concatenation (+, -, &)
  • Not (not)
  • Negate (-)
  • Special (when, format)
  • Literals (true, false, “hello”, 5, 5.0)
Example:

The expression 1 + 2 * 3 is calculated by multiplying 2 and 3 first before adding 1 to the result. Furthermore Boolean and comparison operations happen before any mathematical ones. For instance the expression 2 > 5 + 1 fails the validation check because the Boolean operation greater than is evaluated before the addition, which results in trying to add a false value to 1.

Types of operators

  • Unary: These operators must be used in front of something (e.g. the ‘-‘ in -5).
  • Inset: These operators must be used in the middle of two things (e.g. the ‘+’ in 1 + 1).
  • Supplementary: These operators must be used around two things.
  • Term: This refers to a part of an expression (could be like a word or phrase in a sentence).