Adding a Sub-Report to the JasperReport by JasperReport Plug-in

With the recent release of JasperReport Plug-in, Now, you can directly add any fields, calculations(stored/un-stored), aggregations, global variables, related fields and many more, to your Jasper Report, as you are doing in  Servoy itself. You don’t have write huge SQL Query for the same. Just pass your foundset to the report and access the fields, related fields from the JasperReport basing on the passed foundset. In this TIP, we will  know how we can add a Sub-Report to the Jasper Report and pass a Servoy Foundset to the SubReport.

To add a Sub-Report to your JasperReport at design time with IReport (IReport is the popular Jasper Report Designer tool), you can drag the Sub-Report element from the Element pallet of IReport, to the JasperReport. This will generate the below XML for you.

Where, “Report-Sub.jasper” is your Sub-Report which is going to be added to your JasperReport. To pass a Servoy Foundset to your Sub-Report, you need to specify a Data Source for the Sub-Report. Here, in the above Sub-Report XML, we are passing the Report Field, ‘customers_to_orders’ as the data source for the Sub-Report. We can specify a Report Parameter or a Report Field as Data Source for Sub-Report. But, one IMPORTANT thing that we need to take care of is that, the Parameter or Field MUST be of class “net.sf.jasperreports.engine.JRDataSource”.

Or

And from Servoy you can pass the Servoy Foundset to the Sub-Report, if you are using a Report Parameter as Sub-Report’s Data Source or you need to specify the foundset according to the report Foundset if you are using Report Fields.

150 150 Burnignorance | Where Minds Meet And Sparks Fly!