Expression
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)
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).

Operator | Description | Example |
---|---|---|
& | Use to join two or more strings or fields. | Input Value: FirstName & " " & LastName Result: "John Doe" |
+ | Use to add numbers or decimals. | Input Value: 1 + 1.1 Result: 2.1 |
- | Use to subtract numbers or decimals. | Input Value: 1.1 – 1 Result: 0.1 |
* | Use to multiply numbers or decimals. | Input Value: 1 * 1.1 Result: 1.1 |
/ | Use to divide numbers or decimals. This will always result in a decimal. |
Input Value: 1 / 1.1. Result: 0.909 |
mod | Use to return the remainder after a division. |
Input Value: 16 mod 5 Result: 1 |
pow | Use to apply an exponent (power of) to preceding number. | Input Value: 2 pow 3 Result: 8 |
= | Use to determine if two numbers or fields are equal. Returns Boolean. | Input Value: Price = 500 Result: True |
<> | Use to determine if two numbers are not equal. Returns Boolean. | Input Value: Price <> 400 Result: True |
> | Use to determine if number on left is greater than number on right. Returns Boolean. | Input Value: 2>1 Result: True |
< | Use to determine if number on left is less than number on right. Returns Boolean. | Input Value: 1<2 Result: True |
>= | Use to determine if number on left is greater than or equal to number on right. Returns Boolean. | Input Value: 1>=1 Result: True |
<= | Use to determine if number on left is less than or equal to number on right. Returns Boolean. | Input Value: 1<=1 Result: True |
And | Performed on two Boolean values. Returns True if both values are True, and False if either value is False. | Input Value: True Input Value: False Result: False |
Or | Performed on two Boolean values. Returns True if either value is True, False if both values are False. | Input Value: True Input Value: False Result: True |
Xor | Performed on two Boolean values. Returns True if one and only one value is True. | Input Value: True Input Value: True Result: False |
Not | Negates a value (Boolean). | Input Value:not (1=1) Result: False |
(…) | Surrounds selected items with parentheses. Use for order of operations. | Input Value:(5 + 5) * (4 + 6) Result: 100 |
- (unary) | Negates a value (numeric). | Input Value:-(5 + 5) Result: -10 |
Brackets (Parenthesis or Supplementary)
Brackets behave exactly like they do in math. They force a certain part of the expression to be evaluated before another one is evaluated. You can also use brackets for Boolean and comparison terms. For example:
(true and true) or (false and true) = true or (false and true) = true or false = true
or
(5 > 6) or (6 > 5) = false or (6 > 5) = false or true = true
Not (Unary)
Not simply changes true to false; and false to true.
not true or false = false or false = false
Boolean (Inset)
Boolean operators simply combine two true/false values in certain ways. These ONLY work on true/false (Boolean) values. They are and, or and xor. The following tables give the outcomes.
And (both must be true):
Value 1 | Value 2 | Outcome |
---|---|---|
True | False | False |
True | True | True |
False | False | False |
False | True | False |
Or (either value can be true):
Value 1 | Value 2 | Outcome |
---|---|---|
True | False | True |
True | True | True |
False | False | False |
False | True | True |
Xor (Exclusive or, either can be true, but not both):
Value 1 | Value 2 | Outcome |
---|---|---|
True | False | True |
True | True | False |
False | False | False |
False | True | True |
Comparison (Inset)
The comparison operators determine the size relation between two values. They can be used on numbers, text, dates and time spans.
Multiply (Inset)
The multiply operators are * (multiply), / (divide), mod (modulus) and pow (power). These operators only work on number values. Divide always results in a decimal. Multiply, modulus and power result in the most precise type:
- If any of the two operands are decimal then the result is decimal.
- If both operands are integer then the result is integer.
Addition (Inset)
There are the two mathematical addition operators (+ and -); as well as the string addition (concatenation) operator &. These can also be used on dates and time spans. Please note that the following expression will not result in a concatenation in the expression builder (unlike the K2 text box):
Hello [FieldPart]
It is required to use the string addition operator to concatenate strings.
Negate (Unary)
The negate operator simply turns a number value into it’s negative. For instance:
-(1 + 1) = -2

Operator | Description | Example |
---|---|---|
when | Used to execute one of two sub-expressions based on a condition. |
Input Value: when 1=1 then "yes" otherwise "no" |
format | Used to format a non-textual value into a textual value. | Input Value: 1 format "0.0" Result: 1.0 |
When (Complex)
This operation allows you to select which piece of the expression you would like to execute based on a Boolean (true/false) value. For instance:
when 5 > 10 then Yes otherwise No
= when false then Yes otherwise No
= "No"
More generally, when condition then true part otherwise false part
There are two restrictions:
- The term between when and then must be Boolean (true/false) once it has evaluated.
- The terms between then and otherwise, and the term after otherwise have to be the same type. The following is not a valid expression: when true then Yes otherwise 1
The expression engine does not evaluate the true part or false part if it does not need to. This means if you have a SmartObject create method in the true part and the condition is false then the SmartObject create method is not called.
Format (Inset)
The format operator allows you to format a number, date, etc. according to a certain format string. For instance: [DateField] format "yyyy mm dd". It The standard .Net formatting format is used.
The following online references can be found:
Dates:
- http://msdn.microsoft.com/en-us/library/az4se3k1.aspx
- http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
- http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx
- http://msdn.microsoft.com/en-us/library/0c899ak8.asp

Literal | Description | Example |
---|---|---|
text | Used to create a text value. Start with either " or ' and end the literal with the same character. |
Input Value: "Hello ""Customer""" |
integer | Used to create an integral value. | Input Value: 1 Result: 1 |
decimal | Used to create a real (decimal) value. | Input Value: 1.0 Result: 1.0 |
boolean | Used to create a Boolean value, yes or true; and no or false | Input Value: yes Result: true |
date time | Used to create a date time value. It must be one of the following: [year month day] [year month day hour:minute] [year month day hour:minute:second] |
Input Value: [2001 01 01] Result: First January 2001 Input Value: [1001*2 01 01] Result: First January 2002 |
time span | Used to create a time span. It must be one of the following: [hours:minutes:seconds] [days:hours:minutes:seconds] [days:hours:minutes:seconds:milliseconds] |
Input Value: [15:0:0] Result: 15 hours Input Value: [8*2:0:0:0] Result: 16 days |
Number Literals
Numbers can either be integers or decimals; for example, 5 and 5.1. Remember even 5.0 is a decimal. Exception: When working with mathematical or comparison operators it is valid (unlike functions) to use text. For instance the following is perfectly valid:
"5" + 1
However, if the operator is not mathematical two strings will be left as strings:
"A" > "5"
However if one is a number both will be numbers:
"1" > 2
Finally, these string values are NOT validated – they will only fail at runtime. Validation in this case has been relaxed to make it simpler to use Field Parts that do not have the correct type.
String Literals
Strings are pieces of text. They can start with either a double quote " or a single quote '; they must start and end with the same type of quote. They can contain new lines. To add a quote in the middle of a string, double it up. For instance:
"Dear Customer,
We would like to thank you for the purchase of ""Product"".
Regards
Management"
Or:
'Dear Customer,
We would like to thank you for the purchase of ''Product''.
Management'
Adding a Field Part in the middle of the string can be done in the following way: "Dear " + [Customer] + ","
Boolean Literals
Valid values for Boolean literals are true and false, as well as yes and no.
Date Literals
Dates can be specified in an expression using the following syntax:
[yyyy mm dd]
Or
[yyyy mm dd hh:mm]
Or
[yyyy mm dd hh:mm:ss]
Date and time span literals can also contain operators or field parts in their terms, as long as they evaluate to positive integer values. For example the following expression is valid:
[(1002 * 2) 01 01]
Subtraction:
Two dates can also be subtracted, whether field part or date literal. This results in a time span.
Timespan Literals
You can also specify time differences in an expression. Please note that a TimeSpan cannot be the result of an expression because K2 does not support it outside of the expression builder – it must be used to form a date.
[hh:mm:ss]
Or
[dd:hh:mm:ss]
Or
Timespan behave the same as date literals – you can use operators inside of terms. The following expression will result in a valid Timespan:
[1+1:00:00]
Please note that both the date and Timespan literals have no concept of localization.
Addition:
You can add two time spans (results in a Timespan). You can also add a Timespan to a DateTime which results in a DateTime. Example:
[2010 01 01] + [01:00:00:00]
= [2010 01 02]
Subtraction:
You can subtract two TimeSpans (results in a TimeSpan). This will give you the difference between them. Example:
[03:00:00:00]- [02:00:00:00]
= [01:00:00:00]
As previously stated, this cannot be the final result of an expression and must be used as part of a bigger expression that involves dates.
Negation:
This will make the TimeSpan negative (results in a TimeSpan).

Date Times and Time Spans
The only operator that is valid for two date times is subtraction, which results in a time span.
Time spans can be added, subtracted and negated.
Time spans can be added or subtracted from date times, which results in a date-time.
Text and Field Parts
Field parts should not be nested inside of text literals. The following method is recommended:
"Dear " & <field part> & ",
We would like to thank you for your purchase of """ & <field part> & """.
Management."
Numbers in Text
Text literals can be used instead of numbers, only when:
- They are being used with an inset (in the middle of) operator.
- The literal/value on the other side of the operator is a number.
For example, the following expressions are valid:
- "5" + 1
- "1.1" + 1
- "2" > 3
- <string field part> + 5
Errors are not shown in the expression builder as the expression is evaluated at runtime. If there is an error, the workflow goes into an error state with the details of the error.
Field Parts
Field parts need to have a predetermined type; as such, field parts of the Object or Variant type must be converted to an actual type before using. Note that inline functions can be automatically converted by selecting the correct type within the wizard.