CONDITIONAL RUNNING TOTAL USING VARIABLES

BI PUBLISHER

DOWNLOAD THE PDF HERE

BI Publisher allows the use of variables in a template. The variable is assigned, updated, and displayed using the set_variable and  get_variable syntax. This Tech Tip outlines a simple example to create a running total variable and then how to provide further flexibility by applying a condition to it.

The following is the custom report sample XML used for this Tech Tip.

The initial RTF design template includes a Repeating Group (form fields F and E) for each <CO> row in the XML. Sorted in ascending order by Record No.

Example for BI Publisher Properties for form field F in the Record No column.

Form Fields:

Final Approved Amount is the sum of INITIAL_AMT and ADJUSTED_AMT.

 

The previewed output in PDF:

Running Total using a Variable

 

This example will provide a running total for the Initial Amount.

 

Create a new form field selecting the Initial Amt tag

The variable INITIAL_ RUN_TOT is declared and set (assigned) to a value of 0. The $_XDOCTX syntax allows the variable to be accessible throughout the RTF template (global document text).

 

<?xdoxslt:set_variable($_XDOCTX, ‘INITIAL_ RUN_TOT’,  0)?>

 

Once declared the variable value can be updated accordingly using the following code. In this example, INITIAL_ RUN_TOT is updated within the repeating group. Using the set_variable syntax, the variable is retrieved for each row in the repeating group and the INITIAL_AMT value is added to the  INITIAL_ RUN_TOT value.

 

<?xdoxslt:set_variable($_XDOCTX, ‘INITIAL_ RUN_TOT’, xdoxslt:get_variable($_XDOCTX, ‘INITIAL_ RUN_TOT’) + INITIAL_AMT)?>

 

To display the INITIAL_ RUN_TOT value the get_variable syntax is used.

 

<?xdoxslt:get_variable($_XDOCTX, ‘INITIAL_ RUN_TOT’)?>

 

A new form field is used to display the Initial Amount Running Total. In the Properties tab, select any ‘Data Field’ with Number as the ‘Type’ selection. Enter an appropriate ‘Format’ (format mask) and ‘Text to display’ (as below). The key addition is the display code to enter in the Advanced tab.

The variable declaration syntax is placed at the top of the report outside of the reporting group. The updated code is placed within the repeating group. For easier viewing for this example, the code is entered directly rather than within a form field. The display form field is included in an additional column.

Previewing the output in PDF:

Conditional Running Total using a Variable

 

This example will include a condition of adding to the running total if the Adjusted Amount value is greater than 0. The variable ADJUST_RUN_TOT is declared as before but the update code is modified to support the condition. The value ADJUSTED_AMT is enclosed within an if else condition. If ADJUSTED_AMT is greater than 0 then this value is added to the retrieved ADJUST_RUN_TOT variable otherwise 0 is added (remains the same).

 

<?xdoxslt:set_variable($_XDOCTX, ‘ADJUST_ RUN_TOT’, xdoxslt:get_variable($_XDOCTX, ‘ADJUST_ RUN_TOT’) + xdoxslt:ifelse(ADJUSTED_AMT > 0, ADJUSTED_AMT, 0))?>

 

A new form field is added as in the previous example with the display code referencing the new variable.

 

<?xdoxslt:get_variable($_XDOCTX, ‘INITIAL_ RUN_TOT’)?>

 

The additional code has been added just like the previous example.

Previewing the output in PDF: