Friday, May 02, 2008

BIRT Drill Through

BIRT supports drilling down from a master report to a detail report. To facilitate this feature, BIRT provides a Hyperlink Options builder.



To drill from a table data element, the developer can select the data element, choose the hyperlink property and click on the ellipsis. This will launch the Hyperlink builder. Once the builder is launched, select the Drill-through radial, select either a report design or report document to drill to and supply any needed parameters. Parameters are often based on the current row value of the master table. That is all that is needed to create a master detail report, but suppose you want the detail report to be based on report parameter or some other variable. One way of accomplishing this task is to call the Design Engine API from script and modify the design at runtime.

For example suppose you have a master report and you want the detail report to be based on report parameter. You could define a report parameter for the master report that contains the name of different report designs to be used as a detail. The follow report parameter illustrates doing this with a static list box parameter. Its values are DetailOne and DetailTwo.



Next select the data element that you want to link, select general properties and name the element. In this example it is named mydataelement.




Finally enter script similar to the following in the beforeFactory script event.
importPackage(Packages.org.eclipse.birt.report.model.api);
importPackage(Packages.org.eclipse.birt.report.model.api.elements);


dataHandle = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("mydataelement");

ac = StructureFactory.createAction();
ah = dataHandle.setAction( ac );
ah.setLinkType("drill-through");
ah.setReportName( params["detailrpt"].value +".rptdesign");
ah.setTargetFileType("report-design");
ah.setTargetWindow("_blank");
pb = StructureFactory.createParamBinding();
pb.setParamName("order");
pb.setExpression("row[\"ORDERNUMBER\"]");
ah.addParamBinding(pb);




This code creates a drill-through hyperlink on the fly and sets the detail report based on the report parameter with this line of code:




ah.setReportName( params["detailrpt"].value +".rptdesign");





This example is available at
BIRT Exchange.

17 comments:

Vishal Kharade said...

Hello Jason,

This is really a gr8 help.
But i have done same thing in different way using the rptdocuments of the detail reports and passing them in URL.
In your example can we pass no of parameters to the detail reports.
I have used charts in my example.
I have one question can we call multiple reports on single click on master report.

Thanks in Advance and for really helpful post.
VishalKP

Jason Weathersby said...

VishalKP

That example is passing a parameter, and it could be further refined to go to a rptdocument. Is this what you mean? 2.5 will support multiple drill paths I believe.


Jason

Anonymous said...

Hello Jason,

I'm a newbie to BIRT. Your article is very helpful.

Is it possible to extend the script to allow the master report to pass 2 parameters to either one of the detail reports? Can I add the following lines:
pb1 = StructureFactory.createParamBinding();
pb1.setParamName("putDateTime");
pb1.setExpression("row[\"put_datetime\"]");
ah.addParamBinding(pb1);

Thanks in advance!
Pat

Jason Weathersby said...

Yes this should work as long as the detail report accepts the second parameter.

Jason

Ingo said...

Hi,

is it possible to instead of

ah.setReportName ("BM_MP1-"+params["xy"].value+".rptdesign");


i use row i clicked ... something like this

ah.setReportName ("BM_MP1-"+row["company"].value+".rptdesign");

Jason Weathersby said...

Yes it is possible. Instead of using the beforeFactory script enter something like the following on the data items onCreate event:
var rpt = this.getRowData().getColumnValue("STATUS");
var myaction =this.createAction();
importPackage(Packages.java.util);
var hm = new HashMap();
hm.put("order",row["ORDERNUMBER"]);
this.action = myaction;
var dt =this.action.createDrillThrough();
dt.setReportName(rpt+".rptdesign");
dt.setTargetWindow("_blank");
dt.setTargetFileType("report-design");
dt.setParameterBindings( hm );
myaction.setDrillThrough( dt );

Ingo said...
This comment has been removed by the author.
Ingo said...

Thank you very VERY much :) ...it working perfectly

Anonymous said...

So why exactly is params["myParam"].value not working as param value?

Jason Weathersby said...

Can you give a little more detail on the issue?

matan drory said...

this is working for me on my local computer but failed at the server, is there a way for setReportName not to include the entire path from the server?

it creates a link to /var/.../birt/report/reportname.rptdesign instead of just report/reportname.rptdesign (thats the string i send dt.setReportName("report/" + rpt + ".rptdesign")) where rpt is just a 1 word string

Jason Weathersby said...
This comment has been removed by the author.
Jami said...

Hi,
I am developing this drill through report. I have a master report which summarizes purchase data by year (ex: 2004,2005...) and I want a drill-through report which when i click on year 2004 should show me detail of all the purchase month-wise.
My master report has 5 parameters
1) SupplierID
2) Division
3) Country
4) From Date
5) To date

I am able to pass first 3 parameters but how do i pass 4th parameter? I just want to pass Year from 4th parameter and detail report will show me month-wise purchase of that year.

Thanks,

Jason Weathersby said...

Can you email me your report? my email is jasonweathersby at windstream dot net.

Anonymous said...

hi,
while exporting data to xls duplicate records are showing.
please help.

Jason Weathersby said...

Are you using the default xls emitter? Can you reproduce with the sample db and email me the report?

AlexK said...

"Yes it is possible. Instead of using the beforeFactory script enter something like the following on the data items onCreate..."

Jason, thank you very match for this solution. It`s convenient way create hyperlinks on rows, that you only need.