Switch to: V12V11V10V9V8V7V6V5

Report Object

The root of the VReport JavaScript object model is a Report Object.

It is accessible in all scripts via the report keyword, and all scripts use the same instance of this object.

Report Object has a set of predefined methods and properties listed below.

In addition you can extend it with your OWN methods and properties.

Properties

Methods

Custom Properties

Like any JavaScript object, the report object can be extended with custom properties.

These properties can be used to save intermediate values that should be accessible in all scripts.

Example:

Let's calculate partial sum of “fldAmount” field and output it to the “part_sum_expr” expression field.

We use an expression field to output the calculated value. Label control can't be used for it, because all instances of this control will have the same value.
  • Initialise property in the report pre_build script:
report.partial_sum = 0;
  • Make calculation in the report body pre_place script:
report.partial_sum += report.cursor.columnValue( "fldAmount" );
  • Output value in the “part_sum_expr” pre_place script:
report.controls.part_sum_expr.label = report.partial_sum;

Custom Methods

Report object can be also extended with custom methods. It allows you to write function once and use it in all report scripts multiple times.

Example:

Let you have a field “fldTempF” which has temperature in Fahrenheit, but you need to output it in Celsius in “c_temp_expr”.

  • Declare custom method in the report pre_build script:
report.toCelsius = function( inFahrenheit )
{
    return (5/9) * ( inFahrenheit - 32 );
};
  • Use this method in pre_place script of “c_temp_expr” expression field:
report.controls.c_temp_expr.label = report.toCelsius( report.cursor.columnValue( "fldTempF" ) );