IReport / Jasper Reports – Passing parameters between reports using IReport and Jasper Server
How to send parameter to another in jasper ireport
After i struggled hard for almost a couple of days somewhere in august, for making a connection between two JasperReports (passing parameters from one report to another), these days i was facing the same problem again…so i thought i should write this down before i loose any other minute in the future on the same subject.
The topic is:
Having a Jasper Report, generated with IReport, running on a JasperServer, we want to run a “subreport” by passing a runtime parameter, that was generated in the first report.
As my environment is made up of IReport and JasperServer, running with a JasperServer repository, i was facing two problems:
- How to pass the parameter between two JasperReport reports
- Local vs. Repository Input Controls needed
Point 1 – Passing parameter between reports – Prepare the first report
After you created your first report using IReport (and updated it in the repository), suppose you want to build in a hyperlink, that should run a second report (Report2), by using this parameter as a field in a query for example.
These are the steps to perform:
- In your first report, Report1, right click on the text field containing the book value. Select “hyperlink“
- Select “Hyperlink Type = Report Execution“
- Go to “Link Parameter“, the fourth tab.
- You will have to add two parameters here, both of them of type string:
- _report : “/reports/MyReports/Report2″ - where `_report` is the name of the parameter, and `/reports/MyReports/Report2` is your relative path in the repository, where Report2 is saved. Just replace the path with your own path
- paramrep2 : $F{paramrep1} - where `paramrep2` is the name of the parameter, and `$F{paramrep1}` is the field in your first report, containing the value that you want to send to the second report
- You do not need to add these parameters as parameters in your first report. But you do have to add them in the second, and that takes me to point 2
Point 2 – Preparing the second report for the values passed by the first report
Because we are working with a repository, please try to avoid defining local input controls or datasources.
The parameters sent by Report 1 have to be integrated in Report2 with the help of “input controls”
Define your parameter as an input control in the repository, of the type that you need. Remember it has to have EXACTLY the same name as the parameter defined in Point 1, that being `paramrep2` . After that, refresh the report in IReport, so that you make sure the newly created input control is in the report (check it under the `Input controls` node)
Once you have this settled, you can modify your query accordingly, by using the passed parameter, something like:
where classname=$P{paramrep2}
There it is. It looks straightforward, but we do forget don’t we? And the trick with the repository is a thing to remember (and no, the other way around won’t do it, not with my version of IReport at least, which is 3.5.0)
Hey I was trying to pass params using the above approach but the issue I have is it prompts for the param only in the second report. I want a seamless integration between first and second report. Can you please help me.
Hey this post was extremely helpful, thanks!
hey great post.. but i share the same problem as in the first comment – that when i click on the drill down link the next report prompts for the parameter.. even if i specify the parameter in the url – url….¶meter=11&
i get a prompt with the no. 11 – i have to click ok to see the report
is there away or for it to be seamless..
Thanks in advance
Fabs
Thank s dude, it was very helpful!