Conversion Functions

Conversion functions allow you to convert different types of data.

AsBoolean Function

The AsBoolean function evaluates the expression as True/False.

The Null value is false regardless of the data type.

For a Number expression, 0 is False; otherwise it is True.

For String expressions, Empty String is False; otherwise it is True.

A Date expression is always True.

Syntax:

AsBoolean(expression)

Example:

AsBoolean(1) = True

AsDate Function

The AsDate function attempts to evaluate the expression as a date, if possible.

For example, the string "23/02/1994" will be evaluated as 23/02/1994.

If the expression cannot be evaluated as a date, the function fails and an error is reported.

Null value conversion returns the current date/time.

Number value conversion assumes you are calculating the date starting from 31/12/1899 and adds the given number as the number of days elapsed (for example: AsDate(1) = 31/12/1899).

Syntax:

AsDate(expression)

Example:

AsDate("02\07\2006") = 02\07\2006

AsNumber Function

The AsNumber function evaluates the expression as a number.

Null becomes zero.

True and False are evaluated to 1 and 0, respectively.

A string beginning with a number (or leading spaces followed by a number) returns the number. Any other string is evaluated as 0.

Syntax:

AsNumber(expression)

AsNumber(23ab) is evaluated as 23.

AsNumber(ab23) is evaluated as 23, and "ab" is evaluated as 0.

Example:

AsNumber("5") = 5

AsString Function

The AsString function evaluates the expression as a string.

Null becomes an empty string.

Syntax:

AsString(expression)

Examples:

Expression

Outcome

AsNumber("+24")

24

AsNumber("23rd street")

23

AsNumber("James")

0

AsDate("1/1/2002")

01/01/2002

AsString(12)

the string "12"

AsJsonArray Function

The AsJsonArray function takes multiple comma separated expressions and returns a JSON Array containing the values of the expressions.

This provides a useful way to pass multiple ADORs, variables, or calculated values to another function as a single object. The second function can simply use the JavaScript JSON.parse() function to create a JavaScript array and access the values.

Syntax:

AsJsonArray(expression1, expression2, …)

Example:

AsJsonArray(|->[customerid], @{firstname}, 1+3) = ["ML343","John",4]