Jump to content
We've recently updated our Privacy Statement, available here ×
  • Use a subreport in a report which is connected to an xml datasource


    gregd
    • Features: Reports Version: v4.0, v4.0.2, v4.0.1 Product: iReport Designer

    Subreports are great for many purposes. They are a great way to add data coming from a different datasource or to centralize a piece of a report that is the same in many reports. With subreports you don't need to repeat yourself or do copy/pastes; all you need to do is modify only one subreport instead of many master reports.

    Environment

    This has been verified and tested using iReport 4.0 and higher

    The issue

    What I've found is that when I use xml datasource, the data in the subreport doesn't appear. So I have my subreport using my XML datasource with a Xpath query and when I run it, my chart and table are displayed correctly, but when I include it in a master report and set the subreport to use the main datasource then no data appears.

    The solution

    Because of the nature of the datasource, the datasource isn't passed to the subreport in the usual way. When using an xml datasource you will notice that there are additional default parameters. One of them is XML_DATA_DOCUMENT.

    1. To make sure your data are passed to the subreport you need to go to the properties of the subreport and scrolling down to the bottom, you will find the Parameters property.
    2. Open it using the ellipsis button (Ellipsis_button.png.41ac35569ffb97b4239fbdde1a168515.png) and add a new link to pass a parameter to your subreport. In the Subreport parameter name field you need to enter XML_DATA_DOCUMENT and in the Value expression field pick $P{XML_DATA_DOCUMENT}.

      SubreportParameters.png.f3b0667bd3af7d04ea20d3d0d05045a4.png

    3. Press OK twice
    4. In the sub-report properties you can also find the property Connection type
    5. Select Don't pass data in the Connection type.

      Connection_type.png.8331a775083ff8dcbad145bcc1f679bb.png

    This way the subreport will have access of the xml datasource and should display its content the same way as it does running on its own separatly using that XML datasource.

     


    User Feedback

    Recommended Comments

    Hi, I'm testing Jasper Report v.6.20 using XML Data Source and Subreport.  Both, Report Master and Subreport with XML Data Source,

    I was testing the same XML Data Source for both, and the same but different root expression for Main and Detail rows (Master Report and Subreport).

    Each Report are functioning very well when I execute them separatelly.  But when I execute Master, the data in Subreport appear in blank.

    I used $P {XML_DATA_DOCUMENT}, Report_Connection, and REPORT_DATA_SOURCE, but I cann't.

     

    Someone Can I Help me please!   What' is the tips or workaround using XML_Data_Source in Report with Subreport?

    Thanks in advance

     

    Sue

    Link to comment
    Share on other sites



    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...