Functions¶
Use functions to perform mathematical operations and manipulations to the report data. There are different formulas for string manipulations, date and time and numbers. These are described below:
- Aggregate functions
- String functions
- Math functions
- Date and Time functions
- Operators
- Other Functions
Aggregate Functions¶
Performs different mathematical operations.
Function | Description | Parameters | Example |
---|---|---|---|
sum() | Returns the sum of a repeating numerical item/value within a table | A reference to the item for which you would like to calculate a sum | sum(tns:AMOUNT[.!='']) will sum all amount elements within the iteration and return the result as a number. The "[.!='']" part is added by the framework so that the sum will be valid even if one row in the iteration doesn't contain an amount element or the amount is null |
count() | Returns the count of a repeating item within a table | A reference to the item you would like to count. | count(tns:ROW_NO) will count all ROW_NO elements within the iteration and return the number of occurences. |
avg() | Returns the average value of a repeating numerical item/value within a table. | A reference to the item for which you would like to calculate an average. | vldtaggr:average(tns:SALARY) will calculate an average salary when looping over a number of employees. |
max() | Returns the maximum of a repeating numerical item within a table. | A reference to the item you would like to get the maximum value for. | math:max(tns:SALARY) will return the maximum salary when looping over a number of employees. |
min() | Returns the minimum of a repeating numerical item within a table. | A reference to the item you would like to get the minimum value for. | math:min(tns:SALARY) will return the minimum salary when looping over a number of employees. |
String Functions¶
Performs string manipulations.
Function | Description | Parameters | Example |
---|---|---|---|
strCase(case,list) | Extracts and returns one string from a comma-delimited list of strings, based on the value given in case. | case: Any positive number including zero (0). list: A string composed of comma delimited sub strings. For example: 'dog,cat,horse,mouse,man'. |
strCase(tns:TYPE,'dog,cat,horse,mouse,man') In this example, TYPE is an item with a data type of number. The function strCase returns one of the following depending on the value of TYPE. Case Substring returned 0 dog 1 cat 2 horse 3 mouse 4 man |
concat (string1, string2) |
Concatenates (combines) two strings into one single string value. | string1: The first part of the string. String2: The second part of the string (the one to be appended to the first part). |
concat('ABC', 'XYZ') Would return the string 'ABCXYZ'. |
strCompare(string1, string2) |
Compares the contents of string1 to the contents of string2 and returns a number. | string1 string2 If, string1 < string2 returns a value less than zero (<0) string1 = string2 returns a zero (0) string1 > string2 returns a value greater than zero (>0) |
Returns a value of 1, indicating that ‘dog’ is greater than ‘cat’ if it performs an ASCII sort. |
StrEqualPad(string, length, char) | Maintains the string length at the specified size by either truncating the string, or adding the specified characters to both side of the string equally. |
string: A character value you specify. StrEqualPad adds the specified characters to both left and right sides of the string equally or truncates characters to make this string the length you want. length: Enter the total length of string including padded characters. char: The character to be used as padding. This could be a blank space or any other character as '*', ':', '#' etc. |
StrEqualPad(JOE,6,'*') In this example, the StrEqualPad would return '***JOE***'. Function would pad the contents of the input item JOE with '*' characters equally to the left and right of the string to make it 9 characters in length |
strIff (value,string1, string2,string3) |
Returns a specific string based on the value provided by the value parameter. You can specify a maximum of three strings. | value: A number value you specify, that identifies the string to be returned. string1: A character value you specify. string2: A character value you specify. string3: A character value you specify. Returns If: value < 0 string1 is returned value = 0 string2 is returned value > 0 string3 is returned |
StrIFF(2,'name','address','phone') In this example, the StrIFF function returns the contents of the input item phone. |
strLeft(string,length) | Extracts and returns the specified number of characters, starting the extraction from the left side of the input string. | string: A character value that you specify. length: Any positive number |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StrRTrim('short addresses:', ':') In this example, the StrRTrim function would return the string 'short addresses'. The trailing colon ':' is removed. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StrTranslate(type, list1, list2, default) | Finds the value specified by type in list1 and finds and returns the item in list2 that is in the same position. If not found returns the default value. | type: The comparison variable. Must be a string data type. list1: A string composed of comma delimited look-up values. The contents of type are compared to this list. For example, 'N,S,W,E'. list2: A string composed of comma delimited values, one of which is returned by the function. For example, 'North, South, West, East'. default: A default string value that will be returned if matching item is not found in the list. |
StrTranslate (region, 'N,S,W,E', 'North, South, West, East','North') In this example, region is an input item with a data type of string. The StrTranslate function returns one of the following depending on the value of type. If a matching value for type is not found in the list, 'North' will be returned as a default value. type substring returned N North S South W West E East |
|
|
|
|
|
|
|
|
|
|
|
|
New line | Adds a new line to the XML output. See below for more details. |
|
|
New line¶
This is a String Constant which adds an empty line (also known as a linefeed) to the XML output. The New line constant is represented by $new_line. This can be called inside other string formulas by passing it as any other string parameter. For example if you wish to add/concatenate two strings and add a new line between the two strings, this is the way to do it. Say you need to concatenate 'STRING1' and 'STRING2' using the concat function and display the output in two lines, STRING1 in one line and STRING2 in a new line. You can achieve this output by combining the concat function together with a New line constant as shown below.
concat('STRING1',concat($new_line,'STRING2'))
In the above formula, New line constant is taken in as any other string parameter by the concat function, in this case the string happens to be a new line. The output of the inner concat function is a string that has an empty line and 'STRING2' on the next line. When this is appended to 'STRING1' by the outer concatenate function you can achieve the following output.
Math functions¶
Performs various operations on numbers.
Function | Description | Parameters | Example |
---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GetTotal(list1,list2) | Returns the total of the Sum values for the given two nodes. | list1: first node set in which to calculate the sum. list2: second node set to calculate the sum. |
|
AmountToWords (amount, languageCode, currency) | Returns the amount along with the currency as a translated word | amount: The number to be translated in to words. languageCode: The ifs language code used in runtime. This value can be fetched from the LANG_CODE entry listed under FORMATTING_OPTIONS. One could also use any other XPath value which returns a valid language code. It is also possible to hardcode this value if necessary. currency: Currency to be displayed along with the amount. You could either hardcode this value or use a XPath value which returns a valid currency code supported by IFS. |
Using tns:LANG_CODE from FORMATTING_OPTIONS: vldtmath:AmountToWords (2500.50,/tns:PRINT_CHECK_REP_REQUEST/tns:PROCESSING_INFO/ tns:FORMATTING_OPTIONS/tns:LANG_CODE,tns:CURR_CODE) Using custom XPath for languageCode: vldtmath:AmountToWords(2500.50,tns:LANGUAGE,tns:CURR_CODE) Hardcoded languageCode: vldtmath:AmountToWords(2500.50,'en',tns:CURR_CODE) If runtime values fetched for languageCode is 'en' and currency is 'USD' in the above examples the functions would return two thousand five hundred dollars and fifty cents. |
FormattedNumber(number_format) |
Returns the number as a string after formatting it according to the formatting criteria you specify. See below for more details. |
number_format: number together with the format string. The formatting can be selected from the Format Number dialog shown when selecting a number field. |
concat( FormattedNumber(number), string2) In this example the concat function would return the formatted number as a string append with the string2 parameter. |
FormattedNumber(number_format)¶
If one needs to use a formatted number as a string in a string manipulation operations, for an example in the concat function, then it is made possible by FormattedNumber function.
Say, you need to concatenate the description 'Order Number is:' with a number field and display the number in currency format. Use the concat function to append the description with the number and FormattedNumber to format the number and to return it as a string. The following example displays how it works:
concat('Order Number is:', format:number(tns:ORDER_ID,$language,$country,$variant,'#BASEONLOCALE#','#BASEONLOCALE#','#BASEONLOCALE#','#BASEONLOCALE#','#BASEONLOCALE#','#BASEONLOCALE#','#BASEONLOCALE#','-1.1','true','false'))
Double click on the FormattedNumber function, this will add the function call format:number( ) to the formula editor. Select a number from the Fields section of the Function Editor. When you double click on a number, the Format Number Dialog will show up, in which you specify the type of formatting you would like to have. After setting the formatting click Ok on the Format Number Dialog to continue. The number together with the selected formatting will be written on the function editor.
Remember that formatted numbers cannot be used inside other Number functions.
Date & Time functions¶
Manipulates date and time data fields.
Function | Description | Description | Example |
---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DateMinute(date/time) | Extracts and returns a number representation of the minute (0 to 59) from the input date/time value you provide. | date/time | DateMinute('2004-05-29T15:26:31') In this example the function returns the number 26. |
DateSecond(date/time) | Extracts and returns a number representation of the second (0 to 59) from the input Date/Time value you provide. | date/time | DateSecond('2004-05-29T15:26:31') In this example the function returns the number 31. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns one of date1, date2, or date3, depending on the value returned by the nInput parameter |
|
|
FormattedDateTime(date_and_date_format) | Returns the date as a string after formatting it according to the formatting criteria you specify. See below for more details. |
date and date format: date together with the format string. The formatting can be selected from the Format Date dialog shown when selecting the date field. | concat(string1, concat(FormattedDateTime(date_and_date_format) In this example the two functions, concat and FormattedDateTime will return the formatted date appended to string1. |
FormattedDateTime(date_and_date_format)¶
One can use String functions such as concat to append strings and dates together. However, if one needs to use a formatted date when performing other string manipulations, then this is made possible by the FormattedDateTime function. To explain how this works, let's look at the following example.
Say, you need to concatenate the description 'Order Date is:' with a date field and display the date in medium format and the time in short format. Use the concat function to append the description with the date and FormattedDateTime to format the date as medium and short as shown below.
concat('Order Date is:', format:formatDateTime(tns:ORDER_DATE,$language,$country,$variant,'medium','none','tns:ORDER_DATE'))
Double click on the FormattedDateTime function, this will add the function call format:formatDateTime( ) to the formula editor. Select the date from the Fields section of the Function Editor. When you double click on the date, the Format Date Dialog will show up, in which you specify the type of formatting you'll like to have. After setting the formatting click Ok on the Format Date Dialog to continue. The date together with the selected formatting will be written on the function editor.
Remember that formatted dates cannot be used inside other Date & Time functions.
Operators¶
Helps to perform calculations on numbers.
Function | Description | Example |
---|---|---|
+ operator |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Other Functions¶
These two functions can be used to add text effects
Function | Description | Parameters | Example |
---|---|---|---|
Rotate Text (text, angle) | Rotates the given text by specified angle. Makes it possible to display text in different directions. | text: The text to be rotated. angle: Angle in which to rotate the specified text. |
Rotate Text('Martin',90); the function would return the text rotated clockwise by 90 degrees as: ![]() |
Vertical Text(text) | Returns the specified text vertically from top to bottom. |
text: The text to be written vertically. | Vertical Text('Martin'); will return the text 'Martin' written from top to bottom as:![]() |