Sample 1.3 (TR)

Highlights

- Using TARGET variables to control reporting behavior.

- Using script to implement database driven querying.

Project file:  InstallDir/Samples/TARGET Reports/1.3 Script.report

This sample illustrates how a value stored in a TARGET variable can be used for modification of a custom field and how a database-driven scope can be defined using the OnStartReport context method implementation.

 - Create a TARGET variable. (See scripting)

 - Initialize the default value for the variable. All TARGET variables are available in an external programming environments through automation.  Thus, any kind of data can be passed to a TARGET Reports object from a controlling environment. This sample uses the Rate variable to convert USD to GBR currency through modification of a custom field. The controlling object can be connected to a live feed containing currency rates and can be set up to run reports based on live data. Line 2 from the script sample below changes the field definition based on the value provided by the Rate TARGET variable.

 - Create the OnStartReport context method. (See Scripting)

Implementation of the OnStartReport context method:

'----------------- OnStartReport -----------------

1.   Function OnStartReport

2.      this.SetTermDefinition "Price1", "Freight*" & Rate.value

3.      Dim last_year

4.      last_year = this.GetStatistics( "MAX(OrderDate)" )

5.      last_year = DateAdd( "yyyy", -1, last_year )

6.      this.scope.Modify "OrderDate>" & Target.FormatDate( last_year, "'MM/DD/YYYY'" )

7.   End Function

The database driven query:

Line 4: calculate the maximum value for "OrderDate" field using the GetStatistics report element's method.

Line 5: reduce the calculated date by one year

Line 6: change the report element's scope according to the calculated date.

Now we have a scope that ensures that only last two years stored in the database will take part in the reporting.

Related Sections

Getting Started

TARGET Reports' Concept

User Interface

Samples and Walkthroughs

Programmer's Reference