Jasper Report Downloads


Overview

Helium Rapid version 1.57 introduces functionality to download existing jasper reports directly to a user's machine using normal actions that are triggered by buttons, view actions, widget actions etc.

This is only available for reports that are available in the jasper-reports folder of the app source code.

To trigger a report download from an action, the following is required:

  • A call to the Mez:downloadReport built-in function
  • A submission of the view to Helium's backed. This is done automatically when a DSL_VIEW value or null is returned from the actions function.
  • Upon the next view response, as a result from the above, the download will trigger.

Note that multiple downloads cannot currently be queued. So even if Mez:downloadReport is called multiple times before returning from the action function, only the last download request will be triggered on the user's browser.




Mez:downloadReport

The Mez:downloadReport built-in function can be called as follows:

Mez:downloadReport(DSL_REPORTS.My_Report_Reference, reportArguments, DSL_REPORT_FORMAT.Pdf, optionalFilename)

The arguments specified here are described in the following sections.




Report Reference

DescriptionTypeRequired
A reference to the report as contained in the jasper-reports folder.enum DSL_REPORTSYes

The DSL_REPORTS enum is a new built-in enum provided with Helium Rapid. The values for this enum represents the report within the jasper-reports folder of the app source code.

The values for the enum is derived from the value for the "referenceName" field specified in each report's report.json file.

The values are derived by replacing all spaces with underscores. No underscores are allowed in the value for the "referenceName" field in report.json.

In addition the converted values need to be unique per app and should conform to the normal syntax rules for enums in the DSL.

Consider the following example report.json file:

{
	"name":"All Farmer Purchases",
	"referenceName":"All the Farmer Purchases",
	"actionsDisplay":"close",
	"actionsLabel":"Menu",
	"description":"All farmer purchases system wide",
	"rolesAllowed":["System Admin"]
}

Based on the above report.json the following value will be available in the app:

DSL_REPORTS.All_the_Farmer_Purchases




Report Arguments

DescriptionTypeRequired
The arguments required by the reportjsonYes, but can be empty json such as "{}" if no parameters are specified for the report

The report arguments represent values for the parameters specified in the report.json file for the report.

The key for the argument needs to match the parameter name specified in the report.json file.

In addition the type of the specified argument value should match the type specified in the report.json file. If not, a ProgramException will be thrown by Helium. These exceptions can be handled using the standard try catch functionality available in the DSL.

Consider the following example:

{
	"name":"Your Purchases",
	"referenceName":"Your Purchases",
	"description":"Your purchases",
	"rolesAllowed":["Farmer"],
	"parameters":[
		{
			"parameterName":"startDate",
			"type":"date",
			...
		},
		{
			"parameterName":"endDate",
			"type":"date",
			...
		},
		{
			"parameterName":"shopId",
			"type":"uuid",
			...
		},
		{
			"parameterName":"minCost",
			"type":"string"
			...
		}
	]
}
string downloadPurchases() {
    date startDate = Date:addDays(Mez:now(), -7);
    date endDate = Date:addDays(Mez:now(), 1);
    int minPurchaseAmout = 0;
    uuid shopId = shop._id;

    json args = "{}";
    args.jsonPut("startDate", startDate);
    args.jsonPut("endDate", endDate);
    args.jsonPut("shopId", shopId);
    args.jsonPut("minCost", minPurchaseAmout);

    Mez:downloadReport(DSL_REPORTS.Your_Purchases, args, DSL_REPORT_FORMAT.Pdf);

    return null;
}




Report Format

DescriptionTypeRequired
The file format of the resulting report downloadenum DSL_REPORTS_FORMATYes

The file format for the report download. DSL_REPORTS_FORMAT is a new built-in enum that is available to all apps. The available values are as follows:

  • DSL_REPORTS_FORMAT.Pdf
  • DSL_REPORTS_FORMAT.Xls




Optional File Name

DescriptionTypeRequired
An optional argument for the file name of the resulting downloadstringNo. If not specified the report name as specified in report.json will be used.




Report Privileges

The same access restriction for report display / rendering applies to report downloads from DSL code. 

If "rolesAllowed" is specified in the report's report.json file, those access restrictions will also apply to the Mez:downloadReport built-in function.

If Mez:downloadReport is called from the context of a user who does not have access to the report, a ProgramException will be thrown. These exceptions can be handled using the standard try catch functionality available in the DSL.




Exception Handling

In general, the built-in exception handling provided by the DSL's try catch mechanism can be used to handle exceptions with report generation.

At present, though, SQL exceptions that result from the report's queries cannot be handled in the same way.




Example

View code
<table title="table_title.recent_purchases" csvExport="disabled" cols-md="6">
	    <collectionSource function="getAllShops" />
	    <searchEnabled function="showSearchOnRecentPurchasesShops"/>
	    <column heading="column_heading.shop">
		<attributeName>name</attributeName>
	    </column>
			
	    <rowAction label="button.download_recent_purchases" action="downloadPurchases">
		<binding variable="shop" />
	    </rowAction>
	</table>
Presenter action
string downloadPurchases() {
    date startDate = Date:addDays(Mez:now(), -7);
    date endDate = Date:addDays(Mez:now(), 1);
    int minPurchaseAmout = 0;
    uuid shopId = shop._id;

    json args = "{}";
    args.jsonPut("startDate", startDate);
    args.jsonPut("endDate", endDate);
    args.jsonPut("shopId", shopId);
    args.jsonPut("minCost", minPurchaseAmout);
    Mez:downloadReport(DSL_REPORTS.Your_Purchases_1, args, DSL_REPORT_FORMAT.Pdf);
    return null;
}

View table and download result:

Your Purchases-2.pdf




Additional Mentions and References

Details on other features related to Jasper Reports can be found here: