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 Pet Sematary is Stephen King.", if the variables Book.title and Book.author contain the texts "Pet Sematary" and "Stephen King", 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 this with 100 using the following expression:

Book.price * 100

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

Sub-Expression Type

Notation

Meaning

Text Constant

"text" or >>text<<

Evaluates to the specified text, e.g. "Stephen King", or >>Stephen King<<.

Variables

variablename.attributename

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

Current URL

URL

Evaluates to the URL of the current page.

Subpattern Match

$n

Evaluates to the text matched by subpattern n 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.

The Most Commonly Used Sub-Expression Types


Note that you can specify a text constant using either the quote notation or the >>text<< notation, for example "Stephen King" or >>Stephen King<<. 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. For a complete overview of all functions available, see the reference documentation on expressions.

Function

Meaning

toLowerCase(arg)

Converts the argument to lower case.

round(arg)

Rounds the argument to the nearest integer

The Most Commonly Used Sub-Expression Functions


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.

It is recommended that you experiment with expressions on your own. The best way to experiment with expressions is to launch Design Studio, select the Extract action for the current step, and then add an Advanced Extract data converter. Click the icon to configure the data converter. This opens the Advanced Extract Configuration Window shown below.

The Advanced Extract Configuration Window

In the example shown, note the use of the $n notation to extract parts of the input text. Try to type your own input text into the text area to the left, your own pattern into the "Pattern" property, and your own expression into the "Output Expression" property. You can follow the result in the right area, while typing the expression.

Also, try to click the "Edit..." button to the right of the expression field. This opens the Expression Editor Window shown below.

The Expression Editor Window

In the Expression Editor Window, you can enter an expression and test what it evaluates to. If the expression is associated with a pattern, as in the Advanced Extract data converter, the result of matching the pattern against the current input text will be shown in the "Input" panel. You can see whether the pattern matches, and if so, what subpattern matches your expression can refer to using the $n notation. Note that the testing functionality is not available everywhere in Design Studio.

Click the "Expression" button to open a useful pop-up menu, from which you can choose among the available sub-expression types and functions. This way, you don't have to memorize all of these.

For more on expressions, consult the reference documentation.