Expressions

An expression typically evaluates to a text. For example, the expression

"The author of the book " + Book.title + " is " + Book.author + "." evaluates to the text "The author of the book Gone with the Wind is Margaret Mitchell.", if the variables Book.title and Book.author contain the texts "Gone with the Wind" and "Margaret Mitchell", respectively.

You can also do numeric calculations within the expression. For example, if the variable Book.price contains the price of a book, you can multiply it by 100 using the following expression:

Book.price * 100

The following table provides an overview of the most commonly used sub-expression types. For a complete overview of all available sub-expression types, see the reference below.

Commonly Used Sub-Expression Types

Sub-Expression Type

Notation

Description

Text Constant

"text" or >>text<<

Evaluates to the specified text, e.g. "Margaret Mitchell", or >>Margaret Mitchell<<.

Variables

variablename.attributename

Evaluates to the value of the specified variable, e.g. "Book.author" might evaluate to "Margaret Mitchell".

Current URL

URL

Evaluates to the URL of the current page.

Subpattern Match

$n

Evaluates to the text matched by subpattern in an associated pattern (if any). For example, this is used in the Advanced Extract data converter, as shown below. $0 evaluates to the text matched by the entire pattern.

Function

func(args)

Evaluates the specified function by passing it the specified arguments and converting its result to a text.

Note that you can specify a text constant using either the quote notation or the >>text<< notation, for example "Margaret Mitchell" or >>Margaret Mitchell<<. If you use the quote notation, and you want a quote character to appear inside the text, you have to write it as two quote characters. For example, write "This is some ""quoted"" text" to get the text "This is some "quoted" text". If you use the >>text<< notation, anything can appear inside the text, except ">>" and "<<". Thus, you can write quotes directly, as in >>This is some "quoted" text<<. The >>text<< notation is useful for long texts that contain many quote characters, such as HTML.

The following table shows the most commonly used functions in expressions.

Function

Description

toLowerCase(arg)

Converts the argument to lowercase.

round(arg)

Rounds the argument to the nearest integer.

For example, the expression "The discount is " + round((Item.oldPrice - Item.newPrice) / Item.oldPrice) + "%." evaluates to "The discount is 10%." when the item's old price is $99.95 and the new price is $89.95.

Reference
Expressions

Expression Type

Notation

Description

Examples

Constant

"text"

A fixed text.

You can use the backslash character (\) to enter special characters:

\n for line break

\r for carriage return

\f for form document

\t for horizontal tab

\b for backspace

\" for double quote

\' for single quote

\\ for backslash itself

\uxxxx for the unicode character with encoding xxxx, where xxxx is four hexadecimal digits.

"This is some \"quoted\" text."

"This a text with line break\n, tab \t and a unicode \u0035 character"

Constant

>>text<<

A fixed text. This notation can contain anything, including quote characters, except the end symbol (<<). The backslash (\) character cannot be used to enter special characters.

>>This is some "quoted" text.<<

Variables

variable.attribute

variable

The value of a variable. If the variable is a complex type, an attribute name must also be supplied.

Book.title +

Integer

Input Text

INPUT

The input text, if any, to the expression.

INPUT

Concatenation

expr1 + expr2

The concatenation of the two expressions expr1 and expr2.

"Title:" + Book.title

Subpattern Match

$n

If n > 0, the text that matches subpattern n in the pattern. If n = 0, the text that matches the entire pattern.

Note: This expression has meaning only if there is a pattern associated with the expression.

$1

For more information see Patterns and Experiment with Expressions.

Numeric Expression

Operators: +, -, *, /, %

The result of a numeric expression.

Book.price * 100

Boolean Expression

Operators: && (and), || (or)

The result of a boolean expression.

performTransactions && Book.price < 30

Conditional Expression

condition ? expr1 : expr2

If condition evaluates to true, the value of expr1 is used; otherwise the value of expr2 is used.

Book.price < 30 ? "cheap" : "expensive"

Equality

Operators: == (equal to), != (not equal to)

These operators work on operands of all types, but the type of the operands must be the same. For example, you cannot compare a Number to an Integer.

true == false

style != "none"

Relational

Operators: < (less than), <= (less than or equal to), > (greater than), >= (greater than or equal to)

Relational operators determine if one operand is less than or greater than another operand.

The operands must be numbers, that is of type Integer or Number. The types of the operands in an expression must be the same.

0 < 1

1.0 >= 0.0

Function

func(expr)

The function func applied to the result of the expression expr. See the Functions section that follows this table for the available functions.

capitalize(Book.title)

Current URL

URL

The current URL.

URL

Current Window

WINDOW

The unique ID of the current window.

WINDOW

Robot Name

Robot.name

The name of the robot.

Robot.name

Execution ID

Robot.executionId

The current execution ID of the robot.

Robot.executionId

Execution Errors

Robot.executionErrors

The execution errors encountered in the previous branch of the nearest Try step.

This expression can be used in the second and all subsequent branches of the Try step.

Robot.executionErrors

Functions
Function Description

abs(arg)

Returns the absolute value of the number.

base64Decode(arg)

Decodes Base64 encoded data.

base64Encode(arg)

Encodes binary data with Base64 encoding.

binaryToText(data[, encoding])

Decodes binary data into text. Uses the specified encoding if present, or otherwise defaults to UTF-8 encoding.

capitalize(arg)

Makes the first letter of every word upper case and all other letters lower case.

ceil(arg)

Rounds the number up to the nearest integer.

collapseSpaces(arg)

Makes sure there are no two consecutive spaces.

contains(source, key)

Returns whether the source contains the specified key.

date()

Returns the current date in standard date format (yyyy-mm-dd).

day(args)

Returns the day of month of the date given as an argument.

endsWith(source, key)

Returns true if the source string ends with the specified key, or false otherwise.

floor(arg)

Rounds the number down to the nearest integer.

guid()

Returns a randomly generated, globally unique ID (GUID).

hexDecode(arg)

Decodes hex encoded data.

hexEncode(arg)

Encodes binary data with hex encoding.

indexOf(source, key)

Returns the first index of the key in the source, or -1 if not found.

length(arg)

Counts the number of characters in the text, or the number of bytes if given binary data.

max(a, b)

Returns the greater of the two numbers.

md5(arg)

Computes the MD5 checksum of the binary data given as an argument.

min(a, b)

Returns the smallest of the two numbers.

month(args)

Returns the month of the date given as argument.

now()

Returns the current date and time.

random()

Returns a random number between 0 and 1.

removeSpaces(args)

Removes all white space characters in the argument, such as SPACE, \t, \n.

replacePattern(source, pattern, newText)

Replaces every occurrence of the pattern "pattern" in text "source" with the text "newText". The pattern match is case insensitive.

replaceText(source, oldText, newText)

Replaces every occurrence of the text "oldText" in the text "source" with the text "newText". The match with "oldText" is case insensitive.

resolveURL(arg)

Converts a URL from relative to absolute using the current URL.

round(arg)

Rounds to the nearest integer.

shortTime(arg)

Returns the time without fractional seconds (hh:mm:ss) for the date given as an argument.

substring(source, startIndex)

Returns the portion of the source string starting at the startIndex and up to the end of the source string, with the first character of the string being at index 0.

substring(source, startIndex, endIndex)

Returns the portion of the source string starting at the startIndex and up to the endIndex, with the first character of the string being at index 0.

startsWith(source, key)

Returns true if the source string starts with the specified key, or false otherwise.

textToBinary(text[, encoding])

Encodes text to binary data. Uses the specified encoding if present, or otherwise defaults to UTF-8 encoding.

time(arg)

Returns the time (hh:mm:ss.fff) for the date given as an argument.

toInteger(args)

Converts the text to an integer. This can be useful if you want to include it in calculations.

toNumber(args)

Converts the text to a floating-point number. This can be useful if you want to include it in calculations.

toLowerCase(arg)

Converts all of the characters in the text to lowercase.

toUpperCase(arg)

Converts all of the characters in the text to uppercase.

trim(arg)

Removes all space from both ends of the text.

urlDecode(arg)

Decodes the URL encoded text.

urlEncode(arg)

URL encodes the text.

weekday(arg)

Returns the name of the weekday (in English) for the date given as an argument.

year(args)

Returns the year of the date given as an argument.

toColumn(arg)

Converts integer to Excel column text.

toIndex(arg)

Converts Excel column text to integer.

iteration(arg)

Contains the current iteration number.

Only the expressions that return values of type Text can be used in converters. For more information, see Data Converters.