Global Functions

Global Functions are intended for functional developers to manipulate String, Date, Number and List data visually without coding.

Global Functions can be used when:

Global Functions are possibly executed on either client side or server side. If Global Functions are used in defining ECA rules, they will be executed on client side. If Global Functions are used in defining Data Mapping or conditions of Condition State, they will be executed on server side. Some of Global Functions are only meaningful on server side execution, such as List and Table functions. These functions do not occur in ECA rules definition.

When Global Functions are executed on server side, some of them possibly throw exception. For example, "subString" function possibly throws IndexOutOfBoundsException if the start index is negative. In contrast, when Global Functions are executed on client side, they never throw exception.

For server side global functions, there is a global flag in btt.xml to control the exception handling approach. Developers could define a field element under the kcoll element 'globalFunctions' in Settings. For example,
<field id="ignoreException" value="false"/>
The value "true" means the global function will throw up exceptions to its invocation layer; "false" means the global function will handle the exception in its own logic. The default value is set false.

The following table lists all global functions provides by WebSphere Multichannel Bank Transformation Toolkit, and whether they are supported by server side or client side.
Category Function Name Function Description Is client side Is server side
String compare

Integer compare(String string1, String string2)

Description:
Compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. If a string is null or empty, it is considered to be lexicographically before other string with value.
Argument:
string1 - The string to be compared. The argument can be any string.
string2 - The string to compare. The argument can be any string.
Return:
Returns 0 if string1 is the same as string2.
Returns 1 if string1 is after string2.
Returns -1 if string1 is before strings in dictionary order.
Example:
compare("Hello", "World") returns -1
Y Y
compareIgnoreCase

Integer compareIgnoreCase(String string1, String string2)

Description:
Compares two Strings lexicographically ignoring case differences.
Argument:
string1 - The string to be compared. The argument can be any string.
string2 - The string to compare. The argument can be any string.
Return:
Returns 0 if string1 is the same as string2.
Returns 1 if string1 is after string2.
Returns -1 if string1 is before strings in dictionary order ignoring case difference.
Example:
compareIgnoreCase("Hello", "World") returns -1
Y Y
concat

String concat(String string1, String string2)

Description:
Concatenates two strings.
Argument:
string1 - The string concatenated to the first half part of the returned value. The argument can be any string.
string2 - The string concatenated to the second half part of the returned value. The argument can be any string.
Return:
Returns a string that represents the concatenation of string1's characters followed by the string2's characters.
Example:
concat("Hello ", "World") returns "Hello World"
Y Y
contains

Boolean contains(String string, String subString)

Description:
Returns whether a substring is part of a string.
Argument:
string - The string to be searched. The argument can be any string, if string is null, false will be returned.
subString - The string to search. The argument can be any string, if subString is null, false will be returned.
Return:
Returns true if this string contains subString, false otherwise.
Example:
contains("Hello", "ell") returns true.
contains("Hello", "hey") returns false.
Y Y
getI18NString

String getI18NString(NLS Key)

Description:
Translates BTT format NLS Key to native language string.
Argument:
NLS Key - The Key format is "%packageName/key".
Return:
Returns the string in native language.
Example:
getI18NString("com.ibm.btt.nls.sample/key1")
Y N
indexOf

Integer indexOf(String string, String subString)

Description:
Returns the position of a substring, index starting from 0.
Argument:
string - The string to be searched. The argument can be any string, if string is null, -1 will be returned.
subString - The string to search. The argument can be any string, if it is null, -1 will be returned.
Return:
If the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a subString, -1 is returned.
Example:
indexOf("Hello", "He") returns 0.
indexOf("Hello", "wor") returns -1.
Y Y
lastIndexOf

Integer lastIndexOf(String string, String subString)

Description:
Returns the position of a substring searching from the end, index starting from 0.
Argument:
string - The string to be searched. The argument can be any string, if string is null, -1 will be returned.
subString - The string to search. The argument can be any string, if it is null, -1 will be returned.
Return:
The index within this string of the last occurrence of the specified subString. If it does not occur as a subString, -1 is returned.
Example:
lastIndexOf("Hello", "llo") returns 2.
lastIndexOf("Hello Hello", "llo") returns 8.
Y Y
length

Integer length(String string)

Description:
Returns the length of a string. If string is null, 0 will be returned.
Argument:
string - The string to be calculated. The argument can be any string, if string is null, 0 will be returned.
Return:
Returns the length of string in integer.
Example:
length("Hello") returns 5.
Y Y
lowerCase

String lowerCase(String string)

Description:
Converts to lower case.
Argument:
string - The string to be manipulated. The argument can be any string.
Return:
Returns the String converted to lowercase.
Example:
lowerCase("Hello") returns "hello".
Y Y
upperCase

String upperCase(String string)

Description:
Converts a String to upper case.
Argument:
string - The string to be manipulated. The argument can be any string.
Return:
Returns the String, converted to uppercase
Example:
upperCase("Hello") returns "HELLO".
Y Y
replace

String replace(String string, String oldString, String newString)

Description:
Replaces all occurrences of a substring in a string with a new value.
Argument:
string - The string to be manipulated. The argument can be any string, if it is null, null will be returned.
oldString - The substring to be replaced. The argument can be any string.
newString - The substring to replace oldString.
Return:
Returns the string in which oldString is replaced by newString.
Example:
replace("Hello Hello", "llo", "LLO") returns "HeLLO HeLLO".
Y Y
subString

String subString(String string, Integer start, Integer end)

Description:
Returns a portion of a string.
Argument:
string - The String to be manipulated. The argument can be any string.
start - The beginning index, inclusive. Index starting from 0. The argument can be integer from 0 to length of string.
end - The ending index, exclusive. The arugment can be integer from start to length of string.
Return:
Returns the specified substring from start to end in string.
Exception:
IndexOutOfBoundsException
For server side execution, if the start is negative, or end is larger than the length of this String object, or start is larger than end. For example, subString("hamburger", 10, 2) will cause IndexOutOfBoundsException thrown.
For client side execution, undefined will be returned if the start is negative, or end is larger than the length of this String object, or start is larger than end.
Example:
subString("hamburger", 4, 8) returns "urge".
Y Y
trim

String trim(String string)

Description:
Remove leading and trailing blanks in a string.
Argument:
string - The string to be manipulated. The argument can be any string.
Return:
Returns astring with leading and trailing white space removed.
Example:
trim(" Hello ") returns "Hello".
trim("Hello") returns "Hello".
Y Y
Number absolute

Number absolute(Number number)

Description:
Returns the absolute value of a number.
Argument:
number - The number to be calculated. The argument can by any number.
Return:
Returns the absolute value of the argument. If the number is empty (null), on server side, 0 will be returned, on client side, empty will be returned.
Example:
absolute(15.6) returns 15.6
absolute(-15.6) returns 15.6
Y Y
numberToString

String numberToString(Number number)

Description:
Converts number to string type.
Argument:
number - The number to be converted. The argument can by any number.
Return:
Returns the decimal String representation of this number.
Example:
numberToString(15.6) returns "15.6"
N Y
parseNumber

Number parseNumber(String string)

Description:
Converts string to Double type number.
Argument:
string - The string to be converted. The argument is required to represent a number.
Return:
Returns the double type number represented by string.
Exception:
NumberFormatException - if the string does not contain a parsable number, NumberFormatException will be thrown.
Example:
parseNumber("15.6") returns "15.6"
N Y
round

Integer round(Number number)

Description:
Returns the closest long to the number.
Argument:
number - The number to be calculated. The argument can by any number.
Return:
Returns the closest long to the number. If the number is empty, on server side, 0 will be returned, on client side, empty will be returned.
Example:
round(15.234) returns 15
round(15.5) returns 16
Y Y
truncate

Integer truncate(Number number).

Description:
Returns the truncated value of a number.
Argument:
number - The number to be calculated. The argument can by any number.
Return:
The closest integer less than the number. If the number is empty, on server side, 0 will be returned, on client side, empty will be returned.
Example:
truncate(15.6) returns 15
truncate(-15.6) returns -16
Y Y
Date after

Date after(Date date, Integer days, Integer months, Integer years)

Description:
While calculating the date which is after specified(days, months, years) period than a given date, the process sequence is days, then months and lastly years.
Argument:
date - The date to be calculated. The argument can by any date type data.
days - The number of days after. The argument can be any integer number, if the value is negative, it will be considered as before.
months - The number of months after. The argument can be any integer number, if the value is negative, it will be considered as before.
years - The number of years after. The argument can be any integer number, if the value is negative, it will be considered as before.
Return:
Returns the date which is after than a given date with specified(days, months, years) period. If any of argument is empty, empty value will be returned.
Example:
after(2010/01/20,-5,1,1) returns 2011/02/15.
Y Y
before

Date before(Date date, Integer days, Integer months, Integer years)

Description:
While calculating the date which is before specified(days, months, years) period than a given date, the process sequence is days, then months and lastly years.
Argument:
date - The date to be calculated. The argument can by any date type data.
days - The number of days before. The argument can be any integer number, if the value is negative, it will be considered as after.
months - The number of months before. The argument can be any integer number, if the value is negative, it will be considered as after.
years - The number of years before. The argument can be any integer number, if the value is negative, it will be considered as after.
Return:
Returns the date which is before than a given date with specified(days, months, years) period. If any of argument is empty, empty value will be returned.
Example:
before(2010/01/20,5,-1,1) returns 2009/02/15.
Y Y
day

Integer day(Date date)

Description:
Returns the date of the day in a month in integer.
Argument:
date - The date to be calculated. The argument can by any date type data.
Return:
Returns the date of the day in a month in integer.
Example:
If the date in month is 10, returns 10.
Y Y
dayOfWeek

Integer dayOfWeek(Date date)

Description:
Returns the day of the week in integer.
Argument:
date - The date to be calculated. The argument can by any date type data.
Return:
Returns the day of the week in integer. The first day of week is Sunday, 0 is returned when it is Sunday. If the date is empty, -1 is returned.
Example:
If the day of given date is Monday, return is 1.
If the day of given date is Sunday, return is 0.
Y Y
daysBetween

Double daysBetween(Date date1, Date date2).

Description:
Returns double number representing the days between the two dates in double as time in day is taken into account.
Argument:
date1 - The date to be compared. The argument can by any date type data.
date2 - The date to compare. The argument can by any date type data.
Return:
Returns the days between the two dates in double as time in day is taken into account. If date2 is before date1, negative number will be returned. If any of argument is empty (null), -1 will be returned.
Example:
daysBetween(2010/01/20 12:00:00,2010/01/21 18:00:00) returns 1.25.
daysBetween(2010/01/20 23:00:00,2010/01/21 02:00:00) returns 0.125.
daysBetween(2010/01/21 02:00:00,2010/01/20 23:00:00) returns -0.125.
Y Y
month

Integer month(Date date)

Description:
Returns the month of the date in integer, starting from 0.
Argument:
date - The date to be calculated. The argument can by any date type data.
Return:
Returns the month of the date in integer. 0 represents January.
Example:
If the month of given date is January, returns 0.
If the month of given date is December, returns 11.
Y Y
natureDaysBetween

Integer natureDaysBetween(Date date1, Date date2)

Description:
Returns integer representing the nature days between the two dates ignoring time difference.
Argument:
date1 - The date to be compared. The argument can by any date type data.
date2 - The date to compare. The argument can by any date type data.
Return:
Returns the days between the two dates in integer ignoring time difference. If date2 is before date1, negative number will be returned. If any of argument is empty (null), -1 will be returned.
Example:
natureDaysBetween(2010/01/20 12:00:00, 2010/01/21 18:00:00) returns 1.
natureDaysBetween(2010/01/20 23:59:59, 2010/01/21 00:00:01) returns 1.
natureDaysBetween(2010/01/21 00:00:01, 2010/01/20 23:59:59) returns -1.
Y Y
parseDate

Date parseDate(String date)

Description:
Returns Date type value of given 'date'. The date should be in the format of 'yyyy-MM-dd'.
Argument:
date - the string to be converted to date. The argument need to be string in format of 'yyyy-MM-dd'.
Return:
Returns date type data represented by 'date'.
Exception:
ParseException - for server side execution, if the date is not in the format of 'yyyy-MM-dd' will cause ParseException thrown. For example, parse("2011/12/20") will cause the exception.
Example:
parseDate("2011-12-20") returns the date type data.
Y Y
today

Date today()

Description:
Returns the current date with system default time zone.
Argument:
No
Return:
Returns the date when the function is invoked.
Example:
If the function is invoked on date 2011-12-30, then returns 2011-12-30.
Y Y
toString

String toString(Date date)

Description:
Returns String type value of given 'date' (in the format of 'yyyy-MM-dd').
Argument:
date - the date to be converted to String. The argument can be any date type data.
Return:
Returns the string representing 'date' in the format of 'yyyy-MM-dd'.
Example:
toString(2011-12-30) returns string "2011-12-30"
Y Y
year

Integer year(Date date)

Description:
Returns the year of the date in integer.
Argument:
date - The date to be calculated. The argument can by any date type data.
Return:
Returns the year of the date in integer.
Example:
year(2011-12-30) returns 2011
Y Y
List and Table getRowByIndex

DataElement getRowByIndex(IndexedCollection iColl, Integer index)

Description:
Returns an element in the given 'IColl' List according to the 'index'.
Argument:
iColl - The table to be searched. The argument requires IndexedCollection type data.
index - The index of data element to be retrieved. The argument requires integer from 0 to size of iColl.
Return:
Returns an element in the given 'IColl' List according to the 'index'. If iColl is null or index is more than iColl size, null will be returned.
Example:
The example returns the element in the "accountList" indexed collection that corresponds to index 1. The accountList contains two elements: accountA in index 0 and accountB in index 1, as shown in the following iColl structure definition:
<iColl>accountList
  <kColl>acountA
    <field>accountId: '1001'
    <field>accountAmount: 1000.25
   <kColl>accountB
    <field>accountId: '1002'
    <field>accountAmount: 10000.45

getRowByIndex(accountList,1) returns data element with value:

 <kColl>accountB
    <field>accountId: '1002'
    <field>accountAmount: 10000.45
N Y
  tableAdd

IndexedCollection tableAdd(IndexedCollection iColl, String columnName, Number number)

Description:
Add a numeric value to the given column of the 'IColl' List.
Argument:
iColl - The table to be calculated. The argument requires IndexedCollection type data.
columnName - The name in string of column in table. The argument requires existed column name in iColl table.
number - The value in double to be added. The argument can be any number.
Return:
Returns the table to be added by number. If any of argument is null, null will be returned. If the specified columnName is not found in table, the table with the same content of 'iColl' table will be returned.
Exception:
IllegalArgumentException - If the column specified by columnName does not contain data in number type, IllegalArgumentException will be thrown. User need to ensure the column specified by columnName contains number type data.
Example:
The example returns a new indexed collection in which "accountAmount" column of each element is added by 50 comparing the original "accountList" indexed collection. In this example, the original "accountList" contains two elements: "accountA" in index 0 and "accountB" in index 1, each of them contains a field named "accountAmount", as shown in the following iColl structure definition:
<iColl>accountList
  <kColl>acountA
    <field>accountId: '1001'
    <field>accountAmount: 1000.25
  <kColl>accountB
    <field>accountId: '1002'
    <field>accountAmount: 10000.45

tableAdd(accountList,'accountAmount' 50) returns a table with following value:

 <iColl>accountList
   <kColl>acountA
    <field>accountId: '1001'
    <field>accountAmount: 1050.25
   <kColl>accountB
    <field>accountId: '1002'
    <field>accountAmount: 10050.45
N Y
  tableSize

Integer tableSize(IndexedCollection iColl)

Description:
Returns the number of the elements in the given 'IColl' List.
Argument:
iColl - The table to be calculated. The argument requires IndexedCollection type data.
Return:
Returns the number of the elements in the given 'iColl' List in integer. If 'iColl' is null, 0 will be returned.
Example:
The example returns number of elements in the "accountList" indexed collection. In the example, "accountList" contains two elements: accountA in index 0 and accountB in index 1, as shown in the following iColl structure definition:
<iColl>accountList
  <kColl>acountA
    <field>accountId: '1001'
    <field>accountAmount: 1000.25
  <kColl>accountB
    <field>accountId: '1002'
    <field>accountAmount: 10000.45

tableSize(accountList) returns 2 which is the number of elements in "accountList"

N Y