Functions
Functions are building blocks that you use to create results using operations and expressions. A function returns the result of operations performed on input values. An expression is built by combining operators and values that evaluate during a workflow. Function objects are displayed in gray.
Functions allow you to build simple to complex expressions in any field when designing a workflow. The expressions allow you to calculate dates, concatenate text, do logical and regular expressions, perform math calculations, and perform some file operations. These functions and expressions can be used in rules and as a method to change data coming from another system. Functions are used to both evaluate a condition (true/false) and to return a result, which can be of any type that the K2 platform offers.
The Functions are located within the Context Browser > Function tab.
For example, you can use the Smartfield Composer to reduce an employee's first name to the first letter for use as their initial in an email greeting, using the Left text function.
For more information on how to use the All items as a collection option when configuring SmartObjects within the Smartfield Composer, see the How to: Use the All items as a collection option topic.
The success of a conversion depends on the data itself and not only on the input type. For example, converting a long data type to a short works as long as the data itself is convertible, i.e. the number of bits is 16 or less. Converting a decimal to Boolean works as long as the decimal number is 1.0 or 0.0.
Boolean can be converted from a number, where 1 is true and 0 is false. The following table shows the possible accepted input types:
Function | Accepted input types |
---|---|
To Binary | String (Base-64) |
To Boolean | String, Byte, Short, Integer, Long, Double, Decimal, Boolean |
To Bytes | String |
To DateTime | String |
To Decimal | String, Byte, Short, Integer, Long, Double, Decimal, Boolean |
To Double | String, Byte, Short, Integer, Long, Double, Decimal, Boolean |
To Integer | String, Byte, Short, Integer, Long, Double, Decimal, Boolean |
To Long | String, Byte, Short, Integer, Long, Double, Decimal, Boolean |
To Short | String, Byte, Short, Integer, Long, Double, Decimal, Boolean |
To String | String, Byte, List of Byte, Short, Integer, Long, Double, Decimal, Boolean |
To K2 FQN User | String, String[] |
To SharePoint Claims User | String, String[] |
Functions
Each function is described in the sections below.
Function | Description | Example |
---|---|---|
To Base-64 String |
Converts an array of bytes to a base-64 encoded string. | Input Value: { 69, 120, 97, 109, 112, 108, 101 } Result: "RXhhbXBsZQ==" |
To Binary |
Converts a base-64 encoded string to an array of bytes. |
Input Value: "RXhhbXBsZQ==" Result: { 69, 120, 97, 109, 112, 108, 101 } |
To Boolean |
Converts a value to a Boolean data type. |
Input Value: "1" Result: True |
To Bytes |
Converts a string to an array of bytes using the default character encoding. |
Input Value: "Example" Result: { 69, 120, 97, 109, 112, 108, 101 } |
To Date |
Converts a value to a Date data type. | InputValue: "2017/02/02" Result: 2017/02/02 |
To DateTime |
Converts a value to a DateTime data type. | InputValue: "2017/02/02 05:05:05 AM" Result: 2017/02/02 05:05:05 AM |
To Decimal |
Converts a value to a Decimal Data type. | Input Value: "1" Result: 1.0 |
To Double |
Converts a value to a Double data type. | Input Value: "1" Result: 1.0 |
To Integer |
Converts a value to an Integer data type. | Input Value: "1.0" Result: 1 |
To K2 FQN User |
Converts an encoded SharePoint claims user or group to K2 FQN user or group. |
Example 1:
Example 2:
Result: K2LDAP:joe;K2LDAP:holly |
To K2 FQN User |
Converts an encoded SharePoint claims user or group to K2 FQN user or group. |
Example 1:
Example 2:
Result: K2LDAP:joe;K2LDAP:holly |
To Long |
Converts a value to a Long data type. | Input Value: "1.0" Result: 1 |
To SharePoint Claims User |
Converts a K2 FQN user or group to an encoded SharePoint claims user or group. | Example 1:
Input Value: c:0-.f|ldaproleprovider|legal Result: K2LDAP:legal Example 2: Input Value: c:0-.f|ldaproleprovider|legal;i:0#. f|ldapmembershipprovider|holly Result: K2LDAP:joe;K2LDAP:holly |
To SharePoint Claims User |
Converts a K2 FQN user or group to an encoded SharePoint claims user or group. | Example 1:
Input Value: c:0-.f|ldaproleprovider|legal Result: K2LDAP:legal Example 2: Input Value: c:0-.f|ldaproleprovider|legal;i:0#. f|ldapmembershipprovider|holly Result: K2LDAP:joe;K2LDAP:holly |
To Short |
Converts a value to a Short data type. | Input Value: "1.0" Result: 1 |
To String |
Converts a value to a String data type. |
Input Value: 12345 Result: "12345" Example 2: Input Value: { 69, 120, 97, 109, 112, 108, 101 } Result: "Example" |
To Time |
Converts a value to a Time data type. | InputValue: "05:05:05 AM" Result:05:05:05 AM |
Data functions generates and returns a GUID or updates a Data Field.
Function | Description | Example |
---|---|---|
Generate GUID |
Generates and returns a GUID in string format. |
0f8fad5b-d9cb-469f-a165-70867728950e |
Date and Time functions perform operations on date and time input values and return strings, numbers, or date and time values.
Function | Description | Example |
---|---|---|
Add Days |
Adds a specified number of days to a date. | Date and Time: 01/01/2017 00:00:00 AM Days: 1 Result: 01/02/2017 00:00:00 AM |
Add Hours |
Adds a specified number of hours to a date and time. | Date and Time: 01/01/2017 00:00:00 AM Hours: 1 Result: 01/01/2017 01:00:00 AM |
Add Minutes |
Adds a specified number of minutes to a date and time. | Date and Time: 01/01/2017 00:00:00 AM Minutes: 1 Result: 01/01/2017 00:01:00 AM |
Add Seconds |
Adds a specified number of seconds to a date and time. | Date and Time: 01/01/2017 00:00:00 AM Seconds: 1 Result: 01/01/2017 00:00:01 AM |
Day |
Gets the day of a given date. | Date: 01/01/2017 00:00:00 AM Result: 1 |
Day Difference |
Calculates the number of days between two dates, and hours are decimal fractions. |
Example 1: Example 2: |
End of Month |
Gets the last day of a month. | Year: 2017 Month: 1 Result: 01/31/2017 11:59:59 PM |
End of Quarter |
Gets the last day of a quarter. |
Year: 2017 Result: 03/31/2017 11:59:59 PM |
End of Week | Gets the last day of a week. | Year: 2017 Week: 1 Result: 01/06/2017 11:59:59 PM |
End of Year |
Gets the last day of a year. | Date and Time: 01/01/2017 00:00:00 AM Result: 12/31/2017 11:59:59 PM |
Format Date and Time |
Formats a date and time to a text representation using a specified date and time format. Use the links to see lists of the date and time abbreviations and standard date and time specifiers recognized by the Format Date and Time functions. |
DateTime: 01/01/2017 00:00:00 AM Format: "dddd, dd MMMM yyyy" Result: "Thursday, 1 January 2017 " |
Maximum |
Gets the maximum date and time from a list of values. | Values: {01/01/2017 00:00:00 AM, 01/02/2017 00:00:00 AM }
Result: 01/02/2017 00:00:00 AM |
Minimum |
Gets the minimum date and time from a list of values. | Values: {01/01/2017 00:00:00 AM, 01/02/2017 00:00:00 AM }
Result: 01/01/2017 00:00:00 AM |
Month |
Gets the month of a given date as a number. | Date: 01/01/2017 00:00:00 AM Result: 1 |
Now |
Gets the current date and time. | Result: 06/20/2017 03:34:27 PM |
Quarter |
Gets the quarter number a specified date is in. | Date and Time: 01/01/2017 00:00:00 AM Result: 1 |
Start of Month |
Gets the first day of a month. | Date and Time: 01/02/2017 00:00:00 AM Result: 01/01/2009 00:00:00 AM |
Start of Quarter |
Gets the first day of a quarter. | Date and Time: 01/02/2017 00:00:00 AM Result: 01/01/2017 00:00:00 AM |
Start of Week |
Gets the first day of a week. | Year: 2017 Week: 1 Result: 01/01/2017 00:00:00 AM |
Start of Year |
Gets the first day of a year. | Date and Time: 01/02/2017 00:00:00 AM Result: 01/01/2017 00:00:00 AM |
Subtract Days |
Subtracts a specified amount of days from a date. | Date and Time: 01/01/2017 00:00:00 AM Days: 1 Result: 12/31/2016 00:00:00 AM |
Subtract Hours |
Subtracts a specified amount of hours from a date and time. | Date and Time: 01/01/2017 00:00:00 AM Hours: 1 Result: 12/31/2016 00:23:00 AM |
Subtract Minutes |
Subtracts a specified amount of minutes from a date and time. | Date and Time: 01/01/2017 00:00:00 AM Minutes: 1 Result: 12/31/2016 00:59:00 AM |
Subtract Seconds |
Subtracts a specified number of seconds from a date and time. | Date and Time: 01/01/2017 00:00:00 AM Seconds: 1 Result: 12/31/2016 00:00:59 AM |
Today |
Gets the current day. | Result: 06/20/2017 00:00:00 AM |
Tomorrow |
Return tomorrow's date. | Result: 06/21/2017 00:00:00 AM |
Week Number |
Gets the week number of the year of a specified date. | Date: 01/01/2017 00:00:00 AM Result: 1 |
Weekday |
Gets the name of the day of the week from a specified date. | Date: 01/01/2017 00:00:00 AM Result: "Sunday" |
Year |
Gets the year of a date. | Date: 01/01/2017 00:00:00 AM Result: 2017 |
Yesterday |
Returns yesterday's date. | Result: 06/19/2017 00:00:00 AM |
The following table lists the date and time abbreviations recognized by the Format Date and Time functions.
Date and Time | Abbreviations | Example |
---|---|---|
Year | y, yy, yyyy | 9, 09, 2017 |
Month | M, MM, MMM, MMMM | 2, 02, Feb, February |
Day | d, ddd, dddd | 21, Sat, Saturday |
Hour | h, hh, H, HH | 4, 04, 16, 16 |
Minute | m, mm | 1, 01 |
Second | s, ss | 1, 01 |
Millisecond | ffff | 9999 |
A.M. or P.M. | t, tt | P, PM |
Timezone | z, zz, zzz | -6, -06, -06:00 |
The following table lists the standard date and time specifiers recognized by the Format Date and Time functions.
Specifier | Pattern value (for en-US culture) |
---|---|
t | h:mm tt |
d | M/d/yyyy |
T | h:mm:ss tt |
D | dddd, MMMM dd, yyyy |
f | dddd, MMMM dd, yyyy h:mm tt |
F | dddd, MMMM dd, yyyy h:mm:ss tt |
g | M/d/yyyy h:mm tt |
G | M/d/yyyy h:mm:ss tt |
m, M | MMMM dd |
y, Y | MMMM, yyyy |
r, R | ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (*) |
s | yyyy'-'MM'-'dd'T'HH':'mm':'ss (*) |
u | yyyy'-'MM'-'dd HH':'mm':'ss'Z' (*) |
(*) = culture independent |
The Files inline functions allow you to get information about files, including the content, from various sources.
The return type for all Files inline functions is an XML string. The functions return an XML structure containing the file name and the file contents in Base64, similar to the following:
<files>
<file encoding="Base64">
<name>Leave Policy.docx</name>
<content>JVBERi0xLjSNCiWys7S1...</content>
</file>
</files>
Function | Description | Example |
---|---|---|
Get File From Content |
Gets a file from data fields, expressions, base64-encoded data and other items containing the file’s content, and allows you to specify a file name. | File Name: The name of the file to return. Content: The contents of the file to return passed any object. For example, input text, a combination of expressions or an object from the context browser. Result: The content of the file as an XML string. |
Get Process Attachments |
Gets all process attachments. | Workflow Context's Attachment: Attachments are available from Process Instances of workflows that have Attachments enabled . For more information see How to add and view Workflow comments -->Result: The content of the file as an XML string. |
List functions perform calculations on lists based on input values and returns a number.
Function | Description | Example |
---|---|---|
Contains |
Returns true if the input values are found. |
|
Count |
Counts the number of items in a list of values. Values - Input Number - Return type See How to use the Count Function for further information. |
Input Values: { 1, 2, 3 } Result: 3 |
First Item |
Gets the first value in a list. Values - Input Expected When Empty - Object type. This is returned when the input value is invalid Object - Return value |
Values: {1, 2, 3} Expected When Empty: 0 Result: 1 |
Index Item |
Gets the last value in a list. Values - Object of array type. e.g. output from a Split() function call can be passed into this parameter. When using an XML node, make sure to use the lowest node in the tree. Index - Number of long type. This specifies the 1-based index of the item in the array. Expected When Empty - Object type. This is returned when the input value is invalid or when the index specified is out of bounds. Object - Return value (Object) is the selected object in the array if there are no errors. |
Example 1: Values: { "a", "b", "c" } Index: 1 Expected When Empty: "empty" Result: "a" Example 2: Values: { "a", "b", "c" } Index: 4 Expected When Empty: "empty" Result: "empty" |
Last Item |
Gets the last value in a list. Values - Input Expected When Empty - Object type. This is returned when the input value is invalid Object - Return Value |
Values: {1, 2, 3} Expected When Empty: 0 Result: 3 |
Logical functions performs a logical operation or comparison on objects and expressions, and return a Boolean (True/False) value.
Function | Description | Example |
---|---|---|
And |
Performs an And operation on two Boolean values, returning true if both values are true, false if either value is false. | Input Value: True Input Value: False Result: False |
False |
Gets the Boolean value of false. | Result: False |
No |
Gets the Boolean value of false. | Result: False |
Not |
The Not function changes false to true and true to false. Returns a true value if the condition evaluates to false and a false value if the condition evaluates to true. |
Condition: True Result: False |
Or |
Performs an Or operation on two Boolean values, returning true if one of the values is true, false if both values are false. | Value: True Value: False Result: True |
True |
Gets the Boolean value of true. | Result: True |
Xor |
Performs an Exclusive Or operation on two Boolean values, returning true if one and only one of the values is true. | Value: True Value: True Result: False |
Yes |
Gets the Boolean value of true. | Result: True |
Mathematical functions perform calculations, usually based on input values, and returns a number.
Functions | Description | Example |
---|---|---|
Absolute (Decimal) |
Gets the absolute (positive) value of a number. | Input Value: -1.1 Result: 1.1 |
Absolute (Number) |
Gets the absolute value of a number. | Input Value: -2 Result: 2 |
Average |
Calculates the average of a collection of values. | Input Values: { 1.1, 2.2, 3.3 } Result: 2.2 |
Format Number |
Formats a number to a text representation using a specified numeric format specified. |
Number: 0.111 For more examples, see the Format Number Function - Examples table below. |
Formula |
Use Formula to execute mathematical formulas as a part of rules, mappings, and in notifications. You can only use the following four basic math functions [*, / +, -, and ( )]. You can nest mathematical functions inside another. The exception is you cannot drop a formula function directly into another formula. Tip: When you work with the formula function, always keep in mind the order or operation. PEMDAS (Parentheses, Exponents, Multiplication, Division, Addition, Subtraction) or BODMAS ( Brackets, Of or Order, Division, Multiplication, Addition and Subtraction).
|
Input Value: 4*4 Result: 16 |
Maximum (Decimal) |
Gets the maximum value of a list of values. | Values: { 1.1, 2.2, 3.3 } Expected When Empty: 0 Result: 3.3 |
Maximum (Number) |
Gets the maximum value of a list of values. | Values: { 1, 2, 3 } Expected When Empty: 0 Result: 3 |
Minimum (Decimal) |
Gets the minimum value of a set of values. | Values: { 1.1, 2.2, 3.3 } Expected When Empty: 0 Result: 1.1 |
Minimum (Number) |
Gets the minimum value of a set of values. | Values: { 1, 2, 3 } Expected When Empty: 0 Result: 1 |
Power (Decimal) |
Gets one value raised to the power of another. | Base: 1.1 Power: 1.1 Result: 1.11053424105458 |
Power (Number) |
Gets one value raised to the power of another. | Base: 2 Power: 2 Result: 4 |
Random (Decimal) |
Gets a random number less than or equal to a specified maximum value. | Maximum: 1.2 Result: 0.5810660167974728 |
Random (Number) |
Gets a random number less than or equal to a specified maximum value. | Maximum: 2 Result: 1 |
Random Between (Decimal) |
Gets a random number between two specified values. | Minimum: 0.0 Maximum: 1.2 Result: 0.5810660167974728 |
Random Between (Number) |
Gets a random number between two specified values. | Minimum: 0 Maximum: 2 Result: 1 |
Root (Decimal) |
Gets the positive nth root of a positive number. | Number: 32.0 Nth Root: 5.0 Result: 2.0 |
Root (Number) |
Gets the positive nth root of a positive number. | Number: 100 Nth Root: 2 Result: 10 |
Round |
Rounds a number up or down to a value with a specified precision. | Value: 1.111 Digits: 1 Result: 1.1 |
Round Down |
Rounds a value down. | Value: 1.15 Digits: 1 Result: 1.1 |
Round Up |
Rounds a value up. | Value: 1.15 Digits: 1 Result: 1.2 |
Square (Number) |
Gets the square of a number. | Number: 2 Result: 4 |
Square (Decimal) |
Gets the square of a number. | Number: 1.1 Result: 1.21 |
Square Root (Decimal) |
Gets the square root of a number. | Number: 1.1 Result: 1.04880884817015 |
Square Root (Number) |
Gets the square root of a number. | Number: 100 Result: 10 |
Sum (Number) |
Gets the sum of a selected value. Use a SmartObject reference with a Get List method to configure the sum value. You can only use one value at a time. To sum multiple values, use the Formula function. For more information on how to configure the Sum function, see the How to: Use the Sum Function topic.
|
Drag the SmartObject reference into the Sum value. |
Sum (Decimal) |
Gets the sum of a selected value. Use a SmartObject reference with a Get List method to configure the sum value. You can only use one value at a time. To sum multiple values, use the Formula function. For more information on how to configure the Sum function, see the How to: Use the Sum Function topic.
|
Drag the SmartObject reference into the Sum value. |
Regular Expressions provide a powerful, flexible, and efficient method for processing text. A regular expression is a pattern that the regular expression engine attempts to match in input text.
Functions | Description | Example |
---|---|---|
Match |
For doing a regular expression pattern match of a value. e.g. to check if the input value is a valid E-mail address. Input – Input text to search on. This is a string type. Regex Pattern – Regular expression pattern to use for the search. Case Sensitive – Option to indicate whether the search should be case sensitive or not. Return value (Boolean) - is true if a match was found, otherwise false. |
Example 1:
Example 2:
Example 3:
Note that * will always return a match Example 4:
Example 5:
Matches words ending in 'es' Example 6:
Matches words ending in 'es' |
Match Multiple |
To match multiple values from the input string value using a regular expression pattern. e.g. Finding all claim codes in a text form that has “CLM” in front followed by a fixed 5 digit number. Input – Input text to search on. This is a string type. Regex Pattern – Regular expression pattern to use for the search. Case Sensitive – Option to indicate whether the search should be case sensitive or not. Return value (String[]) - is the array of string values that matched the pattern. If there is no match, it returns No match found. |
Example 1:
Example 2:
Example 3:
Example 4:
|
To |
To match a single value string from the input string value using a regular expression pattern. e.g. Finding a user’s name specified in a text form. Input – Input text to search on. This is a string type. Regex Pattern – Regular expression pattern to use for the search. Case Sensitive – Option to indicate whether the search should be case sensitive or not. Expected When Empty – String type. This is returned when there is no match found or the matched value is empty. Return value (String) - is the matched string if there is a match. |
Example 1:
Example 2:
Example 3:
Example 4:
Example 5:
|
Text functions perform operations such as concatenations or insertions on text. Text-based operations are 1-based, meaning that the index of the first character in a string is 1.
Functions | Description | Example |
---|---|---|
Hyperlink |
Creates a hyperlink with a display name and URL. | Display Name: "K2" URL: "http://www.k2.com" Result: "<a href= http://www.k2.com > K2</a>" |
Contains |
Returns a true value if a substring is found within another string. | Sequence: "12345" Text: "234" Result: True |
Empty String |
Returns an empty string. | Result: "Blank" |
Find |
Returns the index if the specified string is found within another string. Returns 0 if no match can be found. | Substring: "12345" Text: "234" Result: 2 |
Insert |
Inserts a substring into a string at a specified position. | Text: "Example" Substring: "00000" Position: 2 Result: "E00000xample" |
Join |
Concatenates a list of text values or fields, delimiting each with a separator. | Values: { "1", "2", "3" } Separator: ";" Result: "1;2;3" |
Left |
Returns a subset of characters from the left side of a string. | Text: "Test" Length: 1 Result: "T" |
Length |
Returns the length of a string. | Text: "Test" Result: 4 |
Mid |
Returns a subset of characters from a string, starting at a specified index and continuing to the end of the string. | Text: "Example" Start: 3 Result: "ample" |
Pad Left |
Pads a string with a padding character on the left side up to a specified length. | Source String: "Example" Pad Character: "#" Overall Length: 9 Result: "##Example " |
Pad Right |
Pads a string with a padding character on the right side up to a specified length. | Source String: "Example" Pad Character: "#" Overall Length: 9 Result: "Example##" |
Proper |
Converts a string to proper case. | Text: "the quick brown fox jumps over the lazy dog" Result: "The Quick Brown Fox Jumps Over The Lazy Dog" |
Replace |
Replaces a substring within a string with a new substring. | Text: "Ex000le" Find: "000" Replace: "amp " Result: "Example" |
Right |
Returns characters from the right side of a string. | Text: "Example" Length: 3 Result: "ple" |
Split |
Splits text into substrings delimited by a specified separator value. | Text: "a;b;c" Separator: ";" Result: { "a", "b", "c" } |
To Lower |
Converts a string to lower case. | Text: "Example" Result: "example" |
To Upper |
Converts a string to upper case. | Text: "Example" Result: "EXAMPLE" |
Trim |
Removes leading and trailing spaces and line breaks from a string. | Text: " Example" Result: "Example" |
URL Decode |
Encodes a URL string. | URL: "http://local.com/test url.asmx" Result: "http%3a%2f%2flocal.com%2ftest+url.asmx" |
URL Encode |
Decodes a URL string. | URL: "http%3a%2f%2flocal.com%2ftest+url.asmx" Result: "http://local.com/test url.asmx" |