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:

  1. Create a script in Investigate that calls the jsreport API to produce a PDF.

  2. Associate the script to an entity table.

  3. Test the script.

Script creation

  1. Go to Management → Scripts.

  2. Set the Title of the new script to jsreport validation.

  3. Set the Type to sirenapi.

  4. Paste the following into the Source text area:

    const version = 1;
    const type = 'template';
    
    // 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
      }
    });
  5. Click on Save.

Script association

  1. Go to Data Model and click on an entity table or create a new one.

  2. Click on the Template scripts tab.

  3. Click on the Add scripts button.

  4. Click on the play button next to the script created in the previous section.

  5. 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 more information about template scripts see template scripts.

For more information about scripting refer to the Scripting API documentation.