With the recent release of Jasper Report Plug-in, you don’t need to write huge SQL Query for your report. The below TIP will give a quick start introducing the revolutionary change added to the 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 the 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.
If you look at the runReport() Method of the JasperReport plug-in,
plugins.jasperPluginRMI.runReport(source(serverName|foundset), reportFileName , exportFileName / boolean showPrintDialog / printerName, outputFormat, Object parameters, locale])
You will be able to see in the first argument, you can pass a servoy foundset to the report. That passed foundset will be directly be available to the Jasper Report. You can directly access any of the fields of that foundset or any related field from that foundset in the JasperReport.
plugins.jasperPluginRMI.runReport(forms.projects.foundset, "TestJasper.jasper"null , 'view', null);
Here, I am doing a search from Servoy in the projects form based on ‘projects’ table and then passing the result foundset to the Jasper Report, ‘TestJasper.jasper’.
To get the fields of the passed foundset, you need to create a field with the name as of the actual field name. Such as, I want to add the ‘project_name’ field in the report, ‘TestJasper.jasper’, and the ‘project_name’ field is of type String. So, you need to create a field with the same name, ‘project_name’, and set the field class to ‘java.lang.String’. Like below:
Like-wise, you can add any fields to the reports, that the passed foundset is having.
Let’s I would like to add the field, ‘task_name’ of type String to the report. I can reach to the ‘task_name’ field through the relation, ‘projects_tasks’. So, I need to create a field by specifying the total relational hierarchy. Such as:
You can add fields from the relations any level deep. Such as,
Similarly, you can add calculations (stored/un-stored), aggregation by using the same name to the reports.
You can also add a global variable to the report, by following the same procedure.
You can even call a global function from the report and stored the returned value as a field.
Hope, this helps a little in starting with the new JasperReport Plug-in.
JasperReport Plug-in for Servoy is an open source project hosted at Google Code. You can download the Plug-in from here.
For Designing Jasper Reports, there is an open source Jasper Report Designer, IReport, is available in the JasperForge site. You can download IReport from here.