Monday, January 14, 2013

[BI Publisher11g] Dynamic Report Titles


11g has the whole new style templates that include not only externalised headers and footers but also the look and feel for your templates.
In 10g, you can get the headers and footers with a little effort and I have written about them in the past. The recent mails had a small wrinkle in the requirement - they wanted dynamic report titles (or content) passed to the header template. So I could have a template looking like this:
Dynamic Header
With a place holder for the report title, this could be passed at runtime, either as a runtime report parameter or embedded inside the XML data for the report. The Report Name field holds a reference to the passed parameter <?$ReportName?>. The Template Header field contains a reference to the expected inbound report name as a parameter.
<?template:Header?> <?param:ReportName;string('')?>
The 'param' command declares the name of the parameter and sets a default value i.e. in this case an empty string.
We can two approaches to getting the dynamic value into the output. 
XML Data Source
Firstly, we can pull a value from the report's XML data and pass it to the report header sub-template.
We have a standard Import Template command to bring in the sub template. The clear text in the header is a standard call-template command with the added with-param command to pass the report title. You need the @inlines if you want to pass a parameter value.
<?call@inlines:Header?><?with-param:ReportName;.//DEPARTMENT_NAME?> <?end call?>
In this case we are passing the department name from the XML data. I have added a bit more to this template by using the @section in the main grouping statement (group ROW by DEPARTMENT_NAME) This has the effect of re-setting the header each time the DEPARTMENT_NAME changes and thus the 'report title' changes to the new department name.
Report Parameter Source
This is a similar approach.
We just need to declare the report parameter in the main template. The 'Report Param' field contains the parameter declaration.
<?param@begin:val1;'"Employee Report"'?>
That's double quotes surrounding the inner string with single quotes.  The header then contains:
<?call@inlines:Header?><?with-param:ReportName;$val1?> <?end call?>
'with-param' now passes the val1 parameter value to the sub template as $val1. This time the report title will be 'Employee Report' in spite of the @section command i.e, its a fixed constant value that will show on all pages.
You can find the sample templates, data and outputs here