how to dynamically adress a report unit as source for subreports

I have a report that needs to be delivered with a dynamic custom header.

To accomplish this, I used a subreport element that uses a header-type parameter to link to the correct header subreport.

This works fine in Jaspersoft Studio, but i cant get it to work on the server itself.

I already copied the folder structure thats on the server within my developemnt workspace so that path would be the same on both systems but no luck.


I guess I am doing something fundamentally wrong.

I have uploaded my header-subreports as individual report units within a headers folder.

Then, I uploaded the main Report which should use one of the headers depending on a parameter.

No matter how i change the subreport expression, the main report never works, while i can perfectly access the header on its own.

Here is some of the things i tried already, if at all they only worked in the dev studio:

standard path: "/reports/aaaaa/headers/"+$P{P_HEADER}+".jasper"

repo path: "repo:/reports/SecondaryDB/Headers/"+$P{P_HEADER}+".jasper"

tried omitting +".jasper" because i cannot see an actual jasper file, just a report unit.

tried to replace  +".jasper" with  +"/Main.jasper" or "/Main.jrxml"

tried using single or double backslash instead of forward slash

tried using the full external url to the header report


none of that seemed to work.


A thing I have not tried, including the headers right with the main report.

This is because I need to maintain the headers as a single, globally available instance, rather than having compiled copies of them in every single report.


Can someone plase give me an example how this can be achieved?

ronny.dathe's picture
Joined: May 31 2018 - 2:18am
Last seen: 3 years 11 months ago

4 Answers:

Have you uploaded your header - subreports in JasperServer as jrxml files ?

Right-click in the headers folder on one of the jrxml files, and select the "Properties" menu-item

You need to make sure the path-info matches exactly to the "repo:..." syntax, including capitals. It might you have to omit any .jrxml, .jasper extension.

Filip C.'s picture
Joined: May 15 2011 - 11:51pm
Last seen: 4 years 1 month ago

Thanks filipc, got it working.


So apparently, my mistake was to upload the subreports as Report-Unit.

Now I use a plain folder with plain jrxmls, and no file extension in the subreport expression -  that works now.


But the other thing that confused me a lot, is that somehow my subreport expression gets altered while uploading.

My local developement file had it set to "repo:/reports/SecondaryDB/Headers/"+$P{P_HEADER}"

The upladed File had instead "repo:A_SPECIFIC_HEADER" and got rid of the path as well as the parameter, I guess JasperStudio did that implicitly.

I had to open my report unit and manually alter the main.jrxml on the server to set the subreport expressions back to what they should have been.

Only when I found that out, I finally got some results.


Follow-up Question:

Is there a way so I can use the same configuration for local dev as well as on the production server?

Currently I am using Jasper Studios upload function.

Manually altering subreport expressions whenever uploading changes is not exactly an elegant way to roll out reports.

ronny.dathe's picture
Joined: May 31 2018 - 2:18am
Last seen: 3 years 11 months ago

What version of JasperSoft Studio are you using. When you save the report in JasperSoft Studio and it automatically publishes the report to JasperServer as well, it overwrites expressions for subreports, images, ... You have to make sure you do not overwrite those while publishing.


How do you deploy from local DEV to PRD ? I would suggest you do it by using the export/import functionality in JasperServer ... It will automatically copy your DEV structure to the PRD server as well ... You only need to be aware if you also export and import the dependencies, on PRD your datasource connections will be overwritten.


Filip C.'s picture
Joined: May 15 2011 - 11:51pm
Last seen: 4 years 1 month ago

Finally had a chance to test this, as I had to update some headers.

So I selected my updated header files in the local dev space and exported them to a zip archive.

However loading them on the server didnt work. It said "Invalid Export File".

Also tried using the Export to Jasper Server as File option. That however seemed only to do one file at a time although i had multiple selected.

So somehow thats not working either for reliable deployment.


ronny.dathe's picture
Joined: May 31 2018 - 2:18am
Last seen: 3 years 11 months ago