Context Methods (TR)

Implementation of report element context methods is needed when you want to customize some aspects of the report generation procedure. The common tasks requiring such a customization include:

  • customization of aggregate calculations
  • setup of data-driven query
  • dynamic modification of the layout
  • etc.

Context methods are called by TARGET Reports during the report generation process and can be divided into three groups:

1. Methods called once for each reporting element: OnStartReport, OnFinishReport

2. Methods called for each group: OnStartGroup, OnFinishGroup

3. Methods called for each record (applicable only to reports with detailed information): OnRecord

To begin the implementation of a context method, create a placeholder for a new method by typing it into the script editor.  You can also use one of the following three user-interface-based approaches:

I - Drag-and-drop a context method template from the resources pane.

II - Use the Variable's fly menu to create a context method placeholder.

III - Use the script editor's fly menu to:

create a context method

 Find a context method in the script

delete a context method.

OnStartReport

OnStartReport is called before the report generation process is initiated. Implement this method if you want to make any kind of custom preparation for the reporting process like setting the current reporting scope as a function of data stored in a database, dynamic redefinition of your custom fields and so on.

Function: OnStartReport

Parameters:
none

Return value:
none

The sample shows how to use a data-driven scope definition.

Function OnStartReport
Dim last_year
last_year = this.GetStatistics( "MAX(OrderDate)" )
last_year = DateAdd( "yyyy", -1, last_year )
this.scope.Modify "OrderDate>" & Target.FormatDate( last_year, "'MM/DD/YYYY'" )
End Function

OnFinishReport

OnFinishReport is called after the report generation process is completed. One of the reasons this method may need to be implemented is if there is a need to dispose resources allocated in other context methods.

Function OnFinishProcess

Parameters:
none

Return value:
none

OnStartGroup

OnStartGroup is called before each new goup value is processed. Implement this method if you need custom calculation of an aggregate function.

Function OnStartGroup( group_level )

Parameter:
integer group_level - 0 based index of a grouping level, -1 - table (grand total) level.

Return value:
none

OnFinishGroup

OnFinishGroup is called after each group has been processed. Implement this method to override aggregate values with your own custom calculations.

Function OnFinishGroup( group_level )

Parameter:
integer group_level - 0 based index of a grouping level, -1 - table (grand total) level.

Return value:
none

The sample below illustrates how to implement a simple custom aggregate calculation, which is a function of two predefined aggregate functions. Please refer to GetAggregateValue and SetAggregateValue methods for details.

Function OnFinishGroup( n_group )
Dim diff = this.GetAggregateValue( n_group, 1 ) - this.GetAggregateValue( n_group, 0 )
This.SetAggregateValue n_group, 2, diff
End Function

OnRecord

OnRecord is called for each detailed record processed during report generation. One reason to implement this method may be for a custom calculation of an aggregate function.

Function OnRecord

Parameters:
none

Return value:
none

Comments