Jasper report file export
Some Jasper reports must not only be viewed and downloaded by the user, but also archived on the server — the generated report file is written to a server folder, optionally accompanied by a metadata file rendered from a template (for example an <mdas> payload that an external archive such as M3 picks up).
This behavior is opt-in per report and configured entirely through files placed next to the report definition. Enabling it for a new report requires no development work — only the configuration files described below.
How it works
Section titled “How it works”- The user opens the Jasper report in the viewer.
- If an export configuration exists for the report, an extra button appears in the viewer toolbar.
- The user runs the report with real parameters and clicks the button.
- Insight resolves the configured file names from the report’s parameters and result fields, then:
- copies the generated report file to the export folder, and
- if a metadata template exists, renders it and writes the metadata file alongside the report file.
- Both files land in the export folder on the server.
Configuration files
Section titled “Configuration files”Export is configured with files that share the same base name as the report definition and live in the same folder. For a report project_export.jrxml:
project_export.jrxml report definitionproject_export.properties enables and configures the exportproject_export.txt optional metadata template (base name set by report.export.metafile.file)Example project_export.properties:
report.export.enable=YESreport.export.button.caption=Save file to archivereport.export.folder=C:/tmp/jasper_export/export/report.export.filetype=PDFreport.export.filename.pattern=${PARAM_PROJ}_${PARAM_ELNO}_${time.format('yyyyMMdd-HHmmss')}report.export.metafile.type=TXTreport.export.metafile.file=project_exportreport.export.metafile.name.pattern=${PARAM_PROJ}_${PARAM_ELNO}_${time.format('yyyyMMdd-HHmmss')}Property reference
Section titled “Property reference”| Property | Default | Description |
|---|---|---|
report.export.enable | N | Shows the export button when set to a truthy value (YES / true). |
report.export.button.caption | Save file to M3 archive | Text on the toolbar button. |
report.export.folder | engine default export folder | Server folder for the generated files. Path-restricted (see Rules). |
report.export.filetype | PDF | Report output type. |
report.export.filename.pattern | report name | Name pattern for the report file, without file extension. |
report.export.metafile.type | XML | Metadata file type, for example TXT or XML. |
report.export.metafile.file | report name | Base name of the metadata template file (without extension). If no such file exists, no metadata is written. |
report.export.metafile.name.pattern | value of filename.pattern | Name pattern for the generated metadata file, without extension. |
Metadata template
Section titled “Metadata template”The metadata template is a plain text file whose placeholders are filled in when the button is clicked. Example project_export.txt:
<mdas> <entity>Invoice_Attachment</entity> <acl>Fac${queryFields_FACI}</acl> <attrs> <MDS_Name><![CDATA[${PARAM_PROJ}_${PARAM_ELNO}_${time.format('yyyyMMdd-HHmmss')}.pdf]]></MDS_Name> <DATE_XXDT><![CDATA[${time.format('yyyy-MM-dd')}]]></DATE_XXDT> <DIVISION_DIVI><![CDATA[${PARAM_DIVI}]]></DIVISION_DIVI> <PROJECT_ELEMENT_ELNO><![CDATA[${PARAM_ELNO}]]></PROJECT_ELEMENT_ELNO> <PROJECT_NO_PROJ><![CDATA[${PARAM_PROJ}]]></PROJECT_NO_PROJ> </attrs></mdas>Placeholders
Section titled “Placeholders”Placeholders in the file-name patterns and in the metadata template are resolved against the running report:
| Form | Resolves to |
|---|---|
${PARAM_XXX} | report parameter XXX (by name) |
${queryFields_XXX} | field XXX from the report result set |
${time.format('yyyyMMdd-HHmmss')} | the current date/time, formatted |
- Opt-in and file-driven. No export happens unless a
.propertiesfile with the matching base name setsreport.export.enable=YES. - The export folder is path-restricted.
report.export.foldermust be an absolute, normalized path; writes outside the allowed base path are blocked (no..traversal). The Insight process must have write permission to the folder. - Report file names are sanitized. Keep the name patterns unique enough to avoid overwriting previous exports — an existing file with the same name is replaced.
- Metadata is optional. If the template file named by
report.export.metafile.filedoes not exist, only the report file is written.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Likely cause |
|---|---|
| Export button is not visible | .properties file missing, wrong base name, or report.export.enable is not YES. |
| Report file is not created | Export folder does not exist, is not an approved/absolute path, or is not writable by the Insight process. |
| Metadata file is not created | report.export.metafile.file base name or report.export.metafile.type does not match the template file present. |
| A placeholder is left unresolved | The parameter or field name is not available at runtime, or the name does not match exactly. |
${queryFields_...} is empty | The field is not returned by the report query, or the alias does not match the report field name. |