Using the expression builder
The expression builder, shown in Figure 11‑2, is a tool you use to create, modify, and view expressions. It provides a list of the objects, functions, and operators that you can include in expressions. The expression builder is particularly useful when you are learning how to write expressions in JavaScript and discovering which BIRT and JavaScript functions are available.
Figure 11‑2 The expression builder
The expression builder is accessible when you need to specify an expression, such as when you create a computed field in Data Explorer, when you filter data, when you insert a data element, when you specify a data series for a chart, or when you want to display dynamic data in a text element.
You open the expression builder by choosing the button that appears in Figure 11‑3.
Figure 11‑3 The expression builder access button
Creating an expression
The expression builder consists of two parts:
*The top part of the expression builder is where you create or edit an expression. When you choose objects from the bottom part, they appear in this area. You can also type an expression directly in this area.
*The bottom part provides a hierarchical view of the column bindings, report parameters, variables, JavaScript functions, BIRT functions, operators, and data set fields that you can select to build an expression. The items that appear under Category vary, depending on the context of the expression. When you select an item in Category, its contents appear in Sub-Category. When you select an item in Sub-Category, its contents—which you insert in an expression—appear in the box that is the farthest to the right. Figure 11‑4 shows an example.
Figure 11‑4 Functions for String class
Table 11‑1 provides descriptions of the items in the expression builder’s Category column.
Table 11‑1 Categories in the expression builder
Item
Description
Available Column Bindings
Displays the column bindings—references to data set fields or computed data—that are available to the current report element. An element can access column bindings that are defined on the element itself and on the element’s container.
Available Data Sets
Displays the data set or data sets that are available to the current report element. Expand the data sets to select fields to use in an expression. Data set fields are accessible only when you create a column-binding expression or when you create a computed field in the data set editor.
Report Parameters
Displays the report parameters that you created using Data Explorer. Report parameters are typically used to get input from users when they run the report.
Native JavaScript Functions
Displays native JavaScript functions by objects, such as String, Date, Math, and so on. Use these functions to manipulate or calculate data.
For summary information about a function, hover the mouse over the item to display a tooltip. For detailed information, see a JavaScript book.
BIRT Functions
Displays the JavaScript functions that are defined by BIRT. The functions are categorized by objects, such as BirtDateTime, BirtMath, and Finance. Use these functions to calculate data.
For summary information about a function, hover the mouse over the item to display a tooltip. For detailed information, see “Scripting Reference” in BIRT’s online help.
Operators
Displays types of JavaScript operators, such as Assignment, Comparison, Computational, and Logical.
Variables
Displays the report variables that you created using Data Explorer. A report variable has global scope. It is available to any element in the report.
Validating an expression
When you finish creating an expression in the expression builder, choose Validate, as shown in Figure 11‑5, to verify the expression. If the expression is syntactically correct, the expression builder displays the message, No syntax error was found in current script. If the expression contains an error, the expression builder displays a message that describes the error.
Figure 11‑5 Verifying an expression