Convert Using JavaScript
This data converter provides the opportunity to specify the conversion using JavaScript. This data converter may for instance be useful when working with advanced text manipulation such as URL rewriting, or performing complex calculations. For limitations, see Kofax RPA Limitations.
The input to the converter is available in an implicitly defined INPUT variable. The result of performing the conversion must be assigned to an OUTPUT variable. Helper functions can be defined and called if needed. Note that access to the browser state from the JavaScript is not possible in this converter.
Properties
The Convert Using JavaScript data converter is configured using the following properties:
- Script
-
The JavaScript to execute. This may be specified literally or created in several different ways using the Value Selector.
- Description
-
Type in a description to be shown in the list of data converters. If there is no type in a description, one will be generated.
String Manipulation
The following methods are useful when converting String objects. Notice that strings are written inside "" whereas regexp are written within //. A global g attribute at the end of a regexp indicates that the method should apply to all matches.
Method |
Description |
---|---|
string.charAt(n) |
Returns the character with index n. |
string.charCodeAt(n) |
Returns the Unicode value of the character with index n. |
string.concat(value1, value2, ...) |
One or more values are concatenated to string. |
String.fromCharCode(c1, c2, ...) |
Creates a new string from integers specifying the Unicode encodings of the characters. |
string.indexOf(substring) string.indexOf(substring, start) |
Returns the index of substring within string.start specifies the index at which the search should start (0 being the first character in the string and string.length-1 being the last. Default is 0). |
string.lastIndexOf(substring) string.lastIndexOf(substring, start) |
Returns the position of the last occurrence of substring within string.start specifies the index at which the search should start (0 being the first character in the string and string.length-1 (which is default) being the last). |
string.length |
Character length of string. |
string.match(regexp) |
Searches string for matches with a regular expression regexp. Returns only the first match unless regexp has the global attribute specified (g), by which an array containing all results from the match is returned. |
string.replace(regexp, replacement) string.replace(substring, replacement) |
Searches string for matches with a substring or a regular expression and replaces the first occurrence with replacement. If regexp has the global attribute specified (g), all occurrences are replaced with replacement. |
string.search(regexp) |
Returns the index of the first character of the first match with a regular expression. |
string.slice(start, end) |
Returns a string containing all characters from start through end-1. |
string.split(delimiter, limit) |
delimiter is a string or regular expression which specifies the places at which to split string. Returns an array of strings. The array is no longer than limit |
string.substr(start, length) |
Returns a copy of the substring starting from index start and being of the length. |
string.substring(from, to) |
Returns the substring starting at position from and ending at to-1. |
string.toLowerCase() |
Returns a copy of string converted to lower case. |
string.toUpperCase() |
Returns a copy of string with all letters converted to upper case. |
The Math Object
The following properties and methods are useful when doing mathematical computations. All angles are measured in radians.
Property / Method |
Description |
---|---|
Math.E |
Returns Euler's number. |
Math.LN10 |
Returns the natural logarithm of 10. |
Math.LN2 |
Returns the natural logarithm of 2. |
Math.LOG10E |
Returns the base-10 logarithm of E. |
Math.LOG2E |
Returns the base-2 logarithm of E. |
Math.PI |
Returns pi. |
Math.SQRT1_2 |
Returns the square root of 1/2. |
Math.SQRT2 |
Returns the square root of 2. |
Math.abs(x) |
Returns the absolute value. |
Math.acos(x) |
Computes arc cosine. |
Math.asin(x) |
Returns arc sine. |
Math.atan(x) |
Computes arc tangent. |
Math.atan2(y, x) |
Computes the angle to a point. The input represent the usual (x,y)-coordinates, but the order has been reversed. |
Math.ceil(x) |
Rounds up a number. |
Math.cos(x) |
The cosine function. |
Math.exp(x) |
Takes e to the power of x. |
Math.floor(x) |
Rounds down a number. |
Math.log(x) |
Computes the natural logarithm. |
Math.max(x1, x2, ...) |
Returns the largest of the numbers. |
Math.min(x1, x2, ...) |
Returns the smallest of the numbers. |
Math.pow(x,y) |
Computes x to the power of y |
Math.random() |
Returns a random number between 0 and 1 |
Math.round(x) |
Rounds to nearest integer. |
Math.sin(x) |
The sine function. |
Math.sqrt(x) |
Computes the square root. |
Math.tan(x) |
The tangent function. |
Numbers
It is possible to convert from a Number to a String using String(number) and vice versa using Number(string). Here are some of the useful methods of the Number object.
Method |
Description |
---|---|
number.toExponential(digits) |
Specifies the number of digits that will occur after the decimal point. Returns a string representation of number in exponential notation. |
number.toFixed(digits) |
Specifies the number of digits that will occur after the decimal point. Returns a string representation of number that does not use exponential notation. |
number.toPrecision(precision) |
Specifies the number of significant digits. Returns a string representation of number with the specified number of significant digits. |
number.toString(base) |
Returns a string representation of the number using the specified base. |