Creating Single Expression Scripts

Single expression scripts enable you to create "one-liner" expressions to derive report fields. With this facility, you create a formula for calculating a field or an expression that manipulates a string field.

A typical use of a single expression script would be to apply a report parameter to a field; for example, a tax rate or an exchange rate. You could also perform string manipulation. For example, you could take full name fields and extract the first characters of the first names in order to print initials, or you could convert a numeric date into day and month names to aid readability.

Creating these simple expressions requires no coding skills. You select the fields that you want to use in your expression and you select the operator that you want to apply to those fields.

To create a simple single expression script, ensure that the Single Expression option button is selected as the Script Type in the Add Script Field dialog. (This option is selected by default.) For example, if you want to multiply a salary field by a tax rate, the basic procedure is as follows. Select the:

  1. Salary field from a provided list of database fields or report fields.

  2. Multiplication symbol from a provided list of arithmetic operators.

  3. Tax rate field from a provided list of report parameters.

The resulting expression could look like the following.

({Employees::payRoll->salary} * {?taxRate})

To create an expression such as this, you do not have to invent any part of it yourself. You select each of the three parts (that is, the field from which you want to derive the result, the multiplication symbol, and the field by which you want to multiply) from lists that are provided on the Add Script Field dialog.

The expression becomes your script field. When you move the script field to a section of your report, the expression is resolved based on current data each time the section is printed.

For examples of creating single expression scripts, see the following subsection, "Single Expression Script Examples".

The following image shows the Add Script Field dialog after a single expression script has been built (this is the first example described in "Single Expression Script Examples"). The script concatenates (joins together) two address fields, with a comma and a space between them, in order to print them as one field.

For single expression scripts, you have limited use of the available commands (displayed in the Commands list box) and available methods (displayed in the Methods list box). However, all commands and methods, as well as fields and return types, are described in the appendixes listed in the following table.

Script Elements For details, see…
Return Types Chapter 1 of the JADE Encyclopaedia of Primitive Types
Commands Appendix B, "Script Commands"
Fields Appendix C, "Script Fields"
Methods Chapter 1 of the JADE Encyclopaedia of Primitive Types

When you click the Apply button, the full script code is checked by the JADE compiler, to make sure that it is correct and does not cause any errors when it is run as part of a report.

If your expression is in error, the Errors sheet is displayed on the Add Script Field dialog. The most-common error when creating single expressions is using the wrong return type; for example, you are deriving a numeric field and your return type is String, which is non-numeric.

If you encounter errors in your scripts, see "Resolving Errors in Scripts", later in this appendix.