Return Types and Parameters

The majority of primitive type methods listed in this appendix have a return type. As described in "Creating Full Scripts", later in this appendix, the return type is the type of the result value returned to the report script field by the method. For example, the dayName method of the Date primitive type has a return type of String. This means that where the dayName method is applied to a value of type Date, the returned value is a string, containing the day of the week (such as Monday) associated with a specific date.

When there is no return type, the method is one that sets a value of the calling field or executes some other action (for example, saving a file to disk).

JADE is a strongly typed language. This means that where a script method returns a value that will be used for the final output of the field, this must be compatible with the return type defined for the script field. A common source of errors in script fields is incompatible types. For an example of this, see the example method in "Using Intermediate Variables", later in this appendix.

In JADE terms, when a method invokes another method (for example, when the dayName method is used in a script method to find the day associated with a specific date in order to include it in a customized format), it sends a message or calls a method. The method call must follow a specific format (syntax). In JADE, this skeleton structure is known as the signature of the method. As a simplified JADE method, a typical script method has the following syntax.

.method-name ([parameters])

The parameters are a list of parameters for the method. In JADE, a parameter is a value that is passed to another method as part of a method call. These parameters are not to be confused with report parameters, which are used to set up default values that apply throughout a report. A JADE method parameter value is one that affects the operation of the method to which it is passed. For example, the decimalPlaces parameter of the roundedTo method of the Decimal primitive type affects the operation of the method by specifying the number of decimal places to which the returned value is rounded.

Some script methods require parameters. If the script method requires parameters, these are included in the skeleton method call that is inserted into your script code when you select a script method from the Methods list box. For example, the roundedTo method of the Decimal primitive type is displayed in the Script Code sheet, as follows.

.roundedTo(decimalPlaces: Integer)

Parameters are inserted after the method name between parentheses and are separated by semicolons (;). A parameter declaration has the following syntax:

parameter-name : type [usage];

The type of each parameter specified in a method call must correspond to that defined for the parameters of the method. Parameters must be passed in the exact order specified by the parameter list. To define your parameters in a script method, simply delete the parameters of the method signature and replace them with values of the specified type of your own.

If there are no parameters, the parentheses can be left empty or they can be deleted. Alternatively, you can type the method name and parameters directly into the code.

In the following example, the roundedTo method of the Decimal primitive type with a parameter defined as the integer 2 is displayed in the Script Code sheet, as follows.

.roundedTo(2)

This method returns a decimal value rounded to two decimal places.

For script methods, the usage value can be constant or io (input-output). If you do not specify a usage, as is the case with most primitive type methods, a default value of constant is assumed. The parameter usages are as follows.

Further usage options are described in the JADE product information library. If you have access to the JADE documentation, see "Parameters", in Chapter 1 of the JADE Developer’s Reference, for details.