Exporting Bonitasoft BPM Reports to Microsoft Excel

This article is based on Bonitasoft BPM 6.2.1 and is compatible with 6.3.1

Bonitasoft - BPM Reports
Bonitasoft BPM – Reports

Introduction

In any software process, reports are always required to show information and recount any specific events during the process execution. The reporting feature in Bonitasoft BPM is remarkable and adequate enough to export impressive reports. Here’s a comprehensive guide to create reports using the Bonita BPM Studio and iReport Designer, it is one of the best resources from Bonitasoft to get started. The rest of this blog will talk about exporting Bonitasoft BPM reports in PDF and Microsoft Excel formats.

Exporting Bonitasoft BPM Reports in PDF

Let’s export a PDF report first, after going through the documentation of Bonitasoft, reports can be designed using iReport and installed easily in Bonita portal. The output is an automatically previewed HTML format report. What about PDF, Microsoft Excel, CSV, XML, XYX etc.? 

The outlined steps can be followed to export reports in a PDF format.

  1. Once the report design is ready, add a HTML component in iReport designer.
  2. For this component, set the value of HTML Content Exp. property as follow:
"<a style=’some style’ href='runxlsreport" +
$P{BONITA_REPORT_URL}.toString().substring($P{BONITA_REPORT_URL}.toString().indexOf("?"),
$P{BONITA_REPORT_URL}.toString().lastIndexOf("=") + 1) + "PDF&p_date_from=" + $P{_p_date_from} +
"&p_date_to=" + $P{_p_date_to} + "'>Export</a>"

The link points to a location, which appears like http://localhost:8080/bonita/portal/runreport?reportName=MyReport&reportFormat=PDF&p_date_from=1403116199514&p_date_to=1405708199514This HTML link (when clicked) will be taken care by RunReportServlet and gives us a very clean PDF.

RunReportServlet, as the name suggests, is a servlet archived in console-reporting-6.2.1.jar which is responsible for exporting reports either in HTML (default preview) or PDF format.

The reportFormat parameter determines the export format, unfortunately it supports only PDF and HTML. The actual decision for the export format is taken in Exporter class, which also comes along with console-reporting-6.2.1.jar.

Exporting Bonitasoft BPM Reports in Microsoft Excel

Below is the custom implementation process to export Microsoft Excel report. Since the Excel report export handler is unimplemented, a solution has to be found to enable excel report export.

One way is to use the JExcelApiServlet, this servlet expects /portal/runreport/xls in the request and it generates a very basic report and is difficult to be customized.

The other way is to implement our own RunReportServlet and Exporter classes and not manipulate the existing classes because they are very tightly bound. With this option, we have more control on the report elements.

Here are the steps and code snippets for the implementation.

  • Create a class (call it RunXlsReportServlet, any name would be fine) with the content of RunReportServlet.
  • Change the line 
String actionUrlForm = BonitaSystem.<i>getBaseUrl</i>(request) + "/portal/runreport";

to

String actionUrlForm = BonitaSystem.getBaseUrl(request) + "/portal/runxlsreport";
  • Create a class called Exporter and implement the export method as follow:
public static void exportReport(HttpServletRequest request, HttpServletResponse response, ServletContext context, String reportName, String reportFormat, JasperReport report, JasperPrint jasperPrint) throws BonitaReportException {
try {
		response.setHeader("Content-Disposition", " inline; filename=" + reportName + ".xls");
		JRXlsExporter exporterXLS = new JRXlsExporter();
                exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint);
                exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
		exporterXLS.setParameter(JExcelApiExporterParameter.OUTPUT_STREAM, response.getOutputStream());
		response.setContentType("application/vnd.ms-excel");
		exporterXLS.exportReport();
	} catch (JRException e) {
		throw new BonitaReportException("Error during report export (jasperreports)", e);
	} catch (IOException e) {
		throw new BonitaReportException("Error during report export (io)", e);
	}
}
  • Build a jar with the two classes and drop it in \tomcat\webapps\bonita\WEB-INF\lib
  • Add the servlet details in \tomcat\webapps\bonita\WEB-INF\web.xml
<servlet>
<servlet-name>RunXlsReportServlet</servlet-name>
<servlet-class>mypackage.RunXlsReportServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>RunXlsReportServlet</servlet-name>
<url-pattern>/portal/runxlsreport</url-pattern>
</servlet-mapping>

Note: The servlet class is the name of the servlet implementation in step 1 (both should match).

The above steps allow us to configure the server to enable exporting Microsoft Excel reports. To add the Excel export link in the report, add a link (in iReport Designer) which will point to a URL similar to http://localhost:8080/bonita/portal/runxlsreport?reportName=MyReport&reportFormat =xls&p_date_from=1403116199740&p_date_to=1405708199740

Conclusion

Reports are an essential feature to any software, and it is absolutely delightful that Bonitasoft BPM has already provided a generic way of exporting reports in its own style. But with few quick customizations, we were able to export reports without any major effort, which is a great way to start. Hope this article helped you export Bonitasoft BPM reports easily and achieved its goal. Please feel free to drop in a line, if there are any better options to implement any of the above features.

Dayasankar Singh

View posts by Dayasankar Singh
Dayasankar was a Technical Associate at Evoke Technologies. He has extensive technical knowledge on web application design and development with hands on experience on Core Java, Servlets, JSP, Spring (Core, MVC), JSF, Hibernate, Tomcat and Grails.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

%d bloggers like this: