Jump to content
We've recently updated our Privacy Statement, available here ×

how to link two reports ...


sandeepcitigori

Recommended Posts

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Well, I don't think it works with PDF--as far as I know, if you export a report to PDF, normal level 1, 2, 3... bookmarks are just used for navigation within the PDF.  If you want a hyperlink to run another report, I think that only works from within JasperReports server internal view of the report, not from an export.  You didn't mention whether your reports are deployed on JasperReports Server or not.  If they are, I've pasted below my notes on how to get "drill-down" or "drill-up" functionality to work with special Hyperlinks that are set to type "ReportExecution".  I hope they help.

Carl

 

If you have a report that produces details, and you would like to make each detail be a hyperlink that can call another report, potentially passing one or more fields as parameters to the second report, that is called a “drill-down” report.  You can have one report drill down to another and have that report drill down to another (multiple levels).  You could also create a link on a report that returns to the link from which it was called (a “drill-up”?). If the calling report had input parameters, the called report would have to pass those back again, whether the called report actually used them or not, so the calling report has to pass any input parameters to a called report if the called report is going to have “drill-up” functionality.

As an example, let us say that we have a report called SingleState that accepts a state as an input parameter ${TargetState} and generates details that include a field called $F{ADDRESS_CITY}.  Furthermore, let us say that we have a separate report called SingleCity that accepts a state and a city as input parameters $P{TargetState} and $P{TargetCity} and generates details with items from the database that relate to that state and city combination.  Once both reports are working correctly, you can make the first report drill-down to the second report as follows:

1.      In the Report Inspector, right click on the field in the detail record that you want to turn into a hyperlink for the drill-down.  Select “Hyperlink” to bring up the Hyperlink dialog box.

2.      You can leave “Anchor Name Expression” blank, leave “Bookmark Level” at 0, and ignore the “Reference”, “Anchor”, “Page”, and “Tooltip” tabs.  Set “Hyperlink target” to “Self”, and set “Hyperlink type” to “ReportExecution” (from the dropdown control).

3.      In the “Link Parameters” tab, you will need to add each parameter you wish to pass to the subreport, but you will always need to create a parameter with a Paramater name of “_report” (but without the quotation marks), and the Expression will be a repository path like “repo:/Reports/SingleCity” (with quotation marks).  For this example, we also add parameters TargetState and TargetCity (these are the names the report that your are calling uses…and you don’t need $P{} or quotation marks around the names…they’re assumed to be parameter names) and the expression for each of these is $P{TargetState} and $F{ADDRESS_CITY} respectively.  You also need to make sure that the Parameter Class Name (java.lang.String, etc.) agrees with both the expression and the parameter you’ll be supplying.

4.      Notice that iReport preview will not support the hyperlink functionality.  To test the hyperlink functionality, you need to deploy the reports to the repository first and test them there (from JasperServer, typically).  It is best to first test the reports individually once deployed, to be sure they are working correctly independently.  For example, if a report requires input parameters be passed to it, that report requires that Input Controls be added as resources (I believe each Input Control has to have the same name as the parameter it’s supposed to fill), even if you expect that the report will not normally be run as a standalone.  That seems very odd to me, but I’ve tested my drill-down reports with and without input controls, and the parameters do not seem to be filled correctly by the hyperlink unless you have input controls defined.  It is as though the hyperlink is handing values off to presumed input controls instead of to parameters.  I haven’t noticed this same problem with subreports.

5.      Normally, that’s all there is to it!  If you would like to make the SingleCity report have a link in the page header or column header that reads “Click here to see list of cities”, you have to use a Text Field, not a Static Text.  You would then use steps 1 through 3 above, except for the _report parameter, you would specify the SingleState report as the expression, and you wouldn’t have to pass back the city.  You would pass back the TargetState parameter to the SingleState report, passing it the same $P{TargetState} that you received, since at the beginning I said that the SingleState report takes a $P{TargetState} as input.  If you don’t pass this back, I believe you’ll be prompted for a state again, which is probably not what you want.  You want the link at the top of the page to seem like a “Back” button.  In my case, my SingleState report is itself a drill-down from a report that has a fusion map of the United States.  I have a link at the top of my SingleState report that gets me back to that Fusion Map, and it doesn’t have to pass a state or city parameter back to that report.

Link to comment
Share on other sites

Hi cbarlow3, i have tested using your steps but i having below errors:

 

Error Message

 

com.jaspersoft.jasperserver.api.JSExceptionWrapper: Errors were encountered when compiling report expressions class file: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: calculator_report1_1330656686625_286414: 211: expecting ')', found ':' @ line 211, column 27. 1 error

 

Can u please help me.thank u in advance.

Link to comment
Share on other sites

  • 2 weeks later...

 

Thank u for the information.

i did what u said and i deployed report1 and report2 in server.

while running them the report1 output is loaded and i clicked on the department number(hyperlink) and it is transfering to report2 and giving this error.

Error Message:

com.jaspersoft.jasperserver.api.JSExceptionWrapper: Error executing SQL statement for : report2

Please reply me as soon as posible.

Thank you .

Link to comment
Share on other sites

Well, the fact that it's trying to run the second report is a good start.  Here are the things I would troubleshoot:

1. The second report itself.  Have you verified that you can run the second report directly from the repository (not from the report 1 hyperlink) without error?  Obviously, if you can't run it, the link can't run it.

2. There could be a mismatch between the report resource name and what the hyperlink is trying to execute.  I don't think that would give you the error you got (I would expect something more like "resource not found" or something.)  You could actually change the report name in the link to something you know is wrong, just to see if you get the same error or a different one.  If you get a different error (and that's the only change you've made), then you've ruled out a resource name mismatch, and you can set it back the way it was before.  If you suspect a mismatch problem, remember that the link should contain the path to the resource from the repository, and it actually should contain quotation marks.  In my example, the resource name is “repo:/Reports/SingleCity”, because I keep my custom reports in a folder called "Reports", but your repository might be organized differently.  Also, you want the resource name at the end of that to be the resource name, not the display name.

3. There could be a problem where you're not having the first report pass parameters correctly to the second report (if your second report has parameters).  If this is your first time doing a drill-down report, you might consider actually substituting a simpler report that has no parameters as report 2 just to see if you can get any report to run from the hyperlink.  Assuming you have local copies of these jrxml files, just replace report 2 with the newer, simpler report, and delete the input controls you built on the repository.

I guess all of my suggestions boil down to:  get the newest thing you're trying (hyperlink run of a second report) to run something as simple as possible (a report that already works when you run it directly and that has no parameters) and then one-by-one start changing the scenario to be more like the one you need to work in production and re-test to see where you're having a problem.  I could write a few paragraphs on the way to pass parameters to the second report, but what's the point if you're not sure if that's your problem.  Divide the problem until you find the specific area that seems to be breaking the functionality.

Hope that helps!

Carl

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

I have reports to be migrated from actuate to jasper. To my knowledge it has to be implemented in jasper using subreports concept. I have also done adding 2 sub reports in a new report detail section but while previewing i do not see the output however if individually run i can see the output. do i need to add any parameter or to set any connection path? What all settings need to be done to link 2 reports.

Please help me out.

Thanks.

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...