Updated on 2024-10-12 GMT+08:00

Built-in Functions

During intelligent IVR flow orchestration, built-in functions can be used to split and truncate variables in the flow based on site requirements.

  • When the following built-in functions are used for multiple operations, parentheses must be added to subexpressions.
  • In conditional expressions, == can be used for judgment, which applies only to strings and numbers and does not apply to objects or lists (except for null judgment).
Table 1 Built-in functions

Function

Description

length()

Obtains the length of a string.

Example: If there is a flow variable Answer and the value of FLOW.Answer is abcde, you can use the FLOW.Answer.length() expression to obtain the string length of the flow variable Answer. The result is 5.

size()

Obtains the number of elements in a variable of the array or object type.

Example: If there is a flow variable Answer and the value of FLOW.Answer is [1,2,3,4,5], you can use the FLOW.Answer.size() expression to obtain the number of elements of the flow variable Answer. The result is 5.

NOTE:

For an object or array defined by a flow variable, if no default value is set and no value is assigned, the value is not null and the size is 0.

divideString (index, "Separator")

Splits a string.

  • index: Sequence number of the character used for the splitting. The value starts from 1.
  • Separator: If the separator is a regular special character, such as a period (.), dollar sign ($), plus sign (+), vertical bar (|), or asterisk (*), the separator must be enclosed in square brackets, for example, FLOW.XXX.divideString(index,"[+]").

Example: If there is a flow variable Answer and the value of FLOW.Answer is {"UniqueID":"123","ServiceID":"1234","orderid":"12345"}, you can use the FLOW.Answer.divideString(3,",") expression to obtain "orderid":"12345" in the value.

NOTE:

If the value of a list or object uses square brackets or periods and this built-in function needs to be invoked, the value must be cached to a flow variable of the string type before the invocation.

substring(beginIndex, endIndex)

Truncates a string.

  • beginIndex: Start position of the truncation. The value starts from 0. The value 0 indicates the first character.
  • endIndex: End position of the truncation, excluding the character specified by endIndex.

Example: If there is a flow variable Answer and the value of FLOW.Answer is "orderid":"12345", you can use the FLOW.Answer.substring (11, 16) expression to obtain the 12345 in the value.

startsWith("xxx")

Checks whether a variable starts with a string.

Example: If there is a flow variable Answer and the value of FLOW.Answer is abcde, you can use the FLOW.Answer.startsWith("a") expression to check whether the value starts with a. The result is yes. Generally, this function is used in conditional expressions.

endsWith("xxx")

Checks whether a variable ends with a string.

Example: If there is a flow variable Answer and the value of FLOW.Answer is abcde, you can use the FLOW.Answer.endsWith("e") expression to check whether the value ends with e. The result is yes. Generally, this function is used in conditional expressions.

Null check

Checks whether a variable is null.

Example: If there is a flow variable Answer and the value of FLOW.Answer is null, you can use the FLOW.Answer==null or FLOW.Answer!=null expression to check whether the flow variable Answer is null.

+

The following addition operations are supported:

  • String + String = Combined string
  • String + Integer = Combined string
  • Integer + Integer = Addition calculation result

Example: If there are flow variables Str and Num, the value of FLOW.Str is 123, and the value of FLOW.Num is 123,

you can use the FLOW.Str+FLOW.Num expression to obtain the string 123123.

/

Divides a number.

Example: If there are flow variables Num1 and Num2, you can use the FLOW.Num1/FLOW.Num2 expression to assign the result to another flow variable result, which must be of the floating-point number type.

put()

Adds an attribute to an object.

Example: If a flow variable FLOW.person is of the object type and the value is {"name":"Jack"}, you can use FLOW.person.put("age","18") in the cache variable area to add the age attribute to FLOW.person. You can cache the result {"name":"Jack","age":"18"} to any variable of the object type. If a flow variable FLOW.age of the integer type whose value is 18 is available, you can also use FLOW.person.put("age",FLOW.age) to add an attribute. The result is {"name":"Jack","age":"18"}.

NOTE:

In FLOW.person.put(key,value), both key and value can be variable names. If value is a constant, the attribute value is of the string type by default regardless of whether double quotation marks are added. If value is a variable, the data type of the attribute value depends on that of the variable.

add()

Adds an element to a list.

Example: If a flow variable FLOW.arrayList is of the list type and the value is [1], you can use FLOW.arrayList.add(2) in the cache variable area to add an element whose value is 2 to the end of FLOW.arrayList. You can cache the result [1,"2"] to any variable of the list type. If a flow variable FLOW.num of the integer type whose value is 18 is available, you can also use FLOW.arrayList.add(FLOW.num) to add an element. The result is [1,18].

NOTE:

In FLOW.arrayList.add(value), value can be a variable name. If value is a constant, the attribute value is of the string type by default regardless of whether double quotation marks are added. If value is a variable, the data type of the attribute value depends on that of the variable.

Table 2 String operation methods

Function

Description

strSplit()

Splits a string based on a separator.

The return object is the string array generated after splitting. There are two parameters: string to be split and separator.

Example:

If a flow variable FLOW.str is of the string type and the value is "aa,cc,dd,ee", you can invoke this method in the method invocation area to split the string based on a separator (,). You can cache the splitting result to any variable (FLOW.array) of the list type. You can assign values to the method parameters using variables or manually. You do not need to add quotation marks when entering values for the method parameters (the same below).

strSubstring()

Extracts a substring.

The return object is the extracted substring. There are three parameters: string to be truncated, start index (integer), and end index (integer). (The indexes start from 0, and the character with the end index is excluded.)

Example:

If a flow variable FLOW.str is of the string type and the value is "abcdef", you can invoke this method in the method invocation area to extract a substring based on indexes. You can cache the truncation result to any variable (FLOW.result) of the string type. You can assign values to the method parameters using variables or manually.

strIndex0f()

Obtains the index of the first occurrence of a specified string.

The return object is an index, which is an integer. There are two parameters: string to be searched and specified string.

Example:

If a flow variable FLOW.str is of the string type and the value is "abcdef", you can invoke this method in the method invocation area to obtain the index of the first occurrence of a specified string. You can cache the obtained result to any variable (FLOW.result) of the integer type. You can assign values to the method parameters using variables or manually.

strStartsWith()

Checks whether a string starts with a prefix.

The return object is the check result. The value is 0 or 1. There are two parameters: string to be checked and prefix (string).

Example:

If a flow variable FLOW.str is of the string type and the value is "abcdef", you can invoke this method in the method invocation area to check whether the string starts with a prefix. You can cache the check result to any variable (FLOW.result) of the integer type. You can assign values to the method parameters using variables or manually.

strEndsWith()

Checks whether a string ends with a suffix.

The return object is the check result. The value is 0 or 1. There are two parameters: string to be checked and suffix (string).

Example:

If a flow variable FLOW.str is of the string type and the value is "abcdef", you can invoke this method in the method invocation area to check whether the string ends with a suffix. You can cache the check result to any variable (FLOW.result) of the integer type. You can assign values to the method parameters using variables or manually.

strParseJSON()

Converts a JSON string to an object.

The return object is the JSON object generated after conversion. There is one parameter: string to be converted.

Example:

If a flow variable FLOW.strJson1 is of the string type and the value is {"a":"1","b":"2"} in JSON format, you can invoke this method in the method invocation area to convert the string to an object. You can cache the result to any variable (FLOW.obj1) of the object type. You can assign a value to the method parameter using a variable or manually.

strParseInt()

Converts a string to an integer.

The return object is the integer generated after conversion. There is one parameter: string to be converted.

Example:

If a flow variable FLOW.str1 is of the string type and the value is "11", you can invoke this method in the method invocation area to convert the string to an integer. You can cache the result to any variable (FLOW.int1) of the integer type. You can assign a value to the method parameter using a variable or manually.

strParseFloat()

Converts a string to a floating point number.

The return object is the floating point number generated after conversion. There is one parameter: string to be converted.

Example:

If a flow variable FLOW.str1 is of the string type and the value is "0.56", you can invoke this method in the method invocation area to convert the string to a floating point number. You can cache the result to any variable (FLOW.float1) of the floating point number type. You can assign a value to the method parameter using a variable or manually.

strLength()

Obtains the length of a string.

The return object is the string length, which is an integer. There is one parameter: string whose length needs to be calculated.

Example:

If a flow variable FLOW.str1 is of the string type and the value is "qwer", you can invoke this method in the method invocation area to obtain the length of the string. You can cache the result to any variable (FLOW.int1) of the integer type. You can assign a value to the method parameter using a variable or manually.

strToUpperCase()

Converts lowercase in a string to uppercase.

The return object is the string generated after conversion. There is one parameter: string to be converted.

Example:

If a flow variable FLOW.str1 is of the string type and the value is "qwer", you can invoke this method in the method invocation area to convert all letters in the string to uppercase letters. You can cache the result to any variable (FLOW.str1) of the integer type. You can assign a value to the method parameter using a variable or manually.

strToLowerCase()

Converts uppercase in a string to lowercase.

The return object is the string generated after conversion. There is one parameter: string to be converted.

Example:

If a flow variable FLOW.str1 is of the string type and the value is "QWER", you can invoke this method in the method invocation area to convert uppercase in the string to lowercase. You can cache the result to any variable (FLOW.str1) of the integer type. You can assign a value to the method parameter using a variable or manually.

Table 3 Array operation methods

Function

Description

arrayAdd()

Adds an element to an array.

The return object is the addition result. The value is 1 (addition successful) or 0 (addition failed). There are three parameters: array to be modified, position of the addition (by default, the element is added at the end), and element to be added.

Example:

If a flow variable FLOW.array is of the list type and the value is [1,2,3,4], you can invoke this method in the method invocation area to add an element to FLOW.array. The second parameter specifies the position (index) of the addition. You can cache the addition result to any variable (FLOW.result) of the integer type. After the addition is successful, the new value of FLOW.array is [1,2,3,4,5] and is stored in the cache until the flow ends or the value is changed again. You can assign values to the method parameters using variables or manually.

arrayAddAll()

Adds all elements in another set to an array.

The return object is the addition result. The value is 1 (addition successful) or 0 (addition failed). There are three parameters: array to be modified, position of the addition (by default, the elements are added at the end), and elements to be added.

Example:

If flow variables FLOW.array and FLOW.array2 are of the list type and their value are [1,2,3,4] and [5,6,7,8], respectively, you can invoke this method in the method invocation area to add elements in another set to FLOW.array. The second parameter specifies the position (index) of the addition. You can cache the addition result to any variable (FLOW.result) of the integer type. After the addition is successful, the new value of FLOW.array is [1,2,3,4,5,6,7,8] and is stored in the cache until the flow ends or the value is changed again. You can assign values to the method parameters using variables or manually.

arrayContains()

Checks whether an element is in an array.

The return object is the check result. The value is 0 or 1. There are two parameters: array to be checked and element.

Example:

If a flow variable FLOW.array is of the list type and the value is [a,b,c,d], you can invoke this method in the method invocation area to check whether an element is in FLOW.array. You can cache the return result to any variable (FLOW.result) of the integer type. You can assign values to the method parameters using variables or manually.

arrayGet()

Obtains an element from an array based on an index.

The return object is an array element. There are two parameters: array and index.

Example:

If a flow variable FLOW.array is of the list type and the value is [a,b,c,d], you can invoke this method in the method invocation area to obtain an element from FLOW.array based on an index. You can cache the return result to a variable (FLOW.result). You can assign values to the method parameters using variables or manually.

arrayRemoveIdx()

Deletes an element from an array based on an index.

The return object is the deletion result. The value is 1 (deletion successful) or 0 (deletion failed). There are two parameters: array and index.

Example:

If a flow variable FLOW.array is of the list type and the value is [a,b,c,d], you can invoke this method in the method invocation area to delete an element from FLOW.array based on an index. You can cache the deletion result to any variable (FLOW.result) of the integer type. After the deletion is successful, the new value of FLOW.array is [a,b,d] and is stored in the cache until the flow ends or the value is changed again. You can assign values to the method parameters using variables or manually.

arrayRemoveAllIdx()

Deletes elements corresponding to an index set from an array.

The return object is the deletion result. The value is 1 (deletion successful) or 0 (deletion failed). There are two parameters: array and index set.

Example:

If flow variables FLOW.array and FLOW.indexArray are of the list type and their values are [a,b,c,d,e,f] and [2,3,4], respectively, you can invoke this method in the method invocation area to delete elements from FLOW.array based on an index set. The second parameter specifies the index set. You can cache the deletion result to any variable (FLOW.result) of the integer type. After the deletion is successful, the new value of FLOW.array is [a,b,f] and is stored in the cache until the flow ends or the value is changed again. You can assign values to the method parameters using variables or manually.

NOTE:

FLOW.indexArray is an index set of FLOW.array. Its elements support non-negative integers and cannot exceed the maximum index value of FLOW.array.

arrayClear()

Deletes all elements from an array.

The return object is void. The text box is dimmed and cannot be edited. There is one parameter: array to be cleared.

Example:

If a flow variable FLOW.array is of the list type and the value is [a,b,c,d], you can invoke this method in the method invocation area to delete all elements from FLOW.array. After this method is invoked, the new value of FLOW.array is [] and is stored in the cache until the flow ends or the value is changed again. You can assign a value to the method parameter using a variable.

arraySize()

Obtains the length of an array.

The return object is the array length, which is an integer. There is one parameter: array whose length needs to be calculated.

Example:

If a flow variable FLOW.array is of the list type and the value is [a,b,c,d,e,f], you can invoke this method in the method invocation area to obtain the length of FLOW.array. You can cache the obtained result to any variable (FLOW.result) of the integer type. You can assign a value to the method parameter using a variable or manually.

arraySubList()

Truncates and returns a part of an array.

The return object is a subarray. There are three parameters: array to be truncated, start position of the truncation, and end position of the truncation.

Example:

If a flow variable FLOW.array is of the list type and the value is [a,b,c,d,e,f], you can invoke this method in the method invocation area to truncate a part of FLOW.array. You can cache the truncation result to any variable (FLOW.subArray) of the list type. The extracted value (FLOW.subArray) is [c,d,e], includes the character with the start index, and excludes the character with the end index. You can assign values to the method parameters using variables or manually.

arrayJoin()

Converts an array to a string.

The return object is the string generated after conversion. There are two parameters: array to be converted and connection string.

Example:

If a flow variable FLOW.array is of the list type and the value is [a,b,c,d], you can invoke this method in the method invocation area to convert the array to a string based on a symbol. You can cache the conversion result to any variable of the string type (FLOW.result). In the following example, the return result is a=b=c=d. You can assign values to the method parameters using variables or manually.

Table 4 Map operation methods

Function

Description

mapPut()

Adds an element to a map.

The return object is null if the key does not exist or the original value of the object type if the key exists. There are three parameters: map to be modified, key (only the string type is supported), and element to be added.

Example:

If a flow variable FLOW.person is of the object type and the value is {"name":"Jack","sex":"boy"}, you can invoke this method in the method invocation area to add an element to FLOW.person. You can cache the addition result to a variable (FLOW.result). After the addition is successful, the new value of FLOW.person is {"name":"Jack","sex":"boy","age":"25"} and is stored in the cache until the flow ends or the value is changed again. You can assign values to the method parameters using variables or manually.

NOTE:

To manually assign values to the parameters of a variable of the object type, the values cannot be enclosed in double quotation marks. To use flow variables to assign values, refer to the preceding example.

To add list data to a variable of the object type, the third parameter must be a predefined variable. You cannot directly enter an array in the text box. By default, the value in the text box is of the string type.

mapGet()

Obtains the value of a key in a map.

The return object is the value of the key. There are two parameters: map to be processed and key (only the string type is supported).

Example:

If a flow variable FLOW.person is of the object type and the value is {"name":"Jack","sex":"boy"}, you can invoke this method in the method invocation area to obtain the value of a key in the map. You can cache the obtained result to a variable (FLOW.result). You can assign values to the method parameters using variables or manually.

mapRemove()

Deletes a key-value pair from a map.

The return object is the original value of the key in the map or null if the map does not contain the key. There are two parameters: map to be processed and key (only the string type is supported).

Example:

If a flow variable FLOW.person is of the object type and the value is {"name":"Jack","sex":"boy"}, you can invoke this method in the method invocation area to delete a key-value pair from the map. You can cache the deletion result to a variable (FLOW.result). After the deletion is successful, the new value of FLOW.person is stored in the cache until the flow ends or the value is changed again. You can assign values to the method parameters using variables or manually.

mapClear()

Deletes all key-value pairs from a map.

The return object is void. The text box is dimmed and cannot be edited. There is one parameter: map to be cleared.

Example:

If a flow variable FLOW.person is of the object type and the value is {"name":"Jack","sex":"boy"}, you can invoke this method in the method invocation area to clear all key-value pairs from the map. After this method is invoked, the new value of FLOW.person is stored in the cache until the flow ends or the value is changed again. You can assign a value to the method parameter using a variable.

mapSize()

Obtains the total number of keys in a map.

The return object is the number of keys in the map, which is an integer. There is one parameter: map whose number of keys needs to be calculated.

Example:

If a flow variable FLOW.person is of the object type and the value is {"name":"Jack","sex":"boy"}, you can invoke this method in the method invocation area to obtain the total number of keys in the map. After this method is invoked, you can cache the obtained result to any variable (FLOW.result) of the integer type. You can assign a value to the method parameter using a variable.

Table 5 Data operation methods

Function

Description

offsetMonth()

Offsets data by month.

The return object is the offset data, which is a string.

There are two parameters. One is the time variable to be offset, whose value is a string in the format of yyyyMM, for example, 202308. The other is the offset, whose value is an integer and can be negative, for example, -6 (indicating that the source string is offset six months forward).

Example:

If a flow variable FLOW.date is of the string type and the value is 202308, you can invoke this method in the method invocation area to obtain the offset date. After this method is invoked, you can cache the obtained result to any variable (FLOW.result) of the integer type. You can assign a value to the method parameter using a variable.

offsetHour()

Offsets data by hour.

The return object is the offset data, which is a string.

There are two parameters. One is the time variable to be offset, whose value is a string in the format of yyyyMMddHHmmss, for example, 20230808122020. The other is the offset, whose value is an integer and can be negative, for example, -6 (indicating that the source string is offset six hours forward).

Example:

If a flow variable FLOW.date is of the object type and the value is 20230831165801, you can invoke this method in the method invocation area to obtain the offset hour. You can cache the obtained result to a variable (FLOW.result). You can assign values to the method parameters using variables or manually.