About writing expressions
You can create many reports using data that comes directly from a data source simply by dragging the data set fields from Data Explorer to the report. Sometimes, however, you want to display information that is not in the data source, or you want to display data differently from the way it appears in the data source. You might also want to sort data using a formula, rather than sorting on an existing field. For these cases, and many others, write expressions using JavaScript.
An expression is a statement that produces a value. An expression can be a literal value, such as:
3.14
"It is easy to create reports with BIRT"
When you drag a field into the report, BIRT Report Designer creates a column binding with the correct expression. The expression specifies the name of the field from which the report displays values. For example, the following expressions get values from the customerName field and the phone field, respectively:
dataSetRow["customerName"]
dataSetRow["phone"]
An expression can contain any combination of literal values, fields, operators, variables, and functions that evaluates to a single value. In the following examples, the first expression combines static text with a field, the second uses a JavaScript function, and the third multiplies the values of two fields:
"Order Total: " + row["orderTotal"]
row["orderDate"].getYear()
row["itemQuantity"] * row["itemPrice"]
This chapter describes some common uses and examples of expressions in reports. This chapter does not describe all the functions, objects, or operators that you can use in expressions. If you are new to JavaScript, you will find it useful to read a book about JavaScript.