Validating jsreport integration
jsreport bundles a few sample templates that can be used to validate the integration.
In order to produce a report you will need to:
-
Create a script in Investigate that calls the jsreport API to produce a PDF.
-
Associate the script to an entity table.
-
Test the script.
Script creation
-
Go to Management → Scripts.
-
Set the Title of the new script to
jsreport validation
. -
Set the Type to record template.
-
Paste the following into the Source text area:
// The id of the jsreport sample template named "Invoice" const pdfTemplateId = 'rkJTnK2ce'; async function payload() { const payload = { amount: 60000, number: '99', items: [{ name: 'Ice Cream', price: 5000 },{ name: 'Pizza', price: 60000 }] }; return payload; } async function buildPdfDownload() { await sirenapi.Reporting.download(pdfTemplateId, await payload(), 'invoice.pdf'); } context.registerTemplate({ download: { pdf: buildPdfDownload } });
-
Click on Save.
Script association
-
Go to Data Model and click on an entity table or create a new one.
-
Click on the Template scripts tab.
-
Click on the Add scripts button.
-
Click on the play button next to the script created in the previous section.
-
Click on the
.pdf
link inside the preview.
If the integration is working correctly you should obtain a PDF file named invoice.pdf
based on the sample invoice template.
Next steps
For step by step instructions on how to create templates and downloadable reports see templating and reporting.
For more information about template scripts see template scripts.
For more information about scripting refer to the Scripting API documentation.