Validating jsreport integration

You can use the sample templates bundled by jsreport to validate the integration.

To produce a report, you 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.

Creating the script

  1. Go to ManagementScripts.

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

  3. Set the Type to template.

  4. Make sure that Version is set to a value of 2 (default option).

  5. Paste the following into the Source text area:

    function buildPdfDownload() {
      // The id of the jsreport sample template named "Invoice"
      const templateId = 'rkJTnK2ce';
    
      const data = {
        amount: 60000,
        number: 99,
        items: [
          {
            name: 'Ice Cream',
            price: 5000
          },
          {
            name: 'Pizza',
            price: 60000
          }
        ]
      };
    
      return { filename: 'invoice.pdf', templateId, data };
    }
    
    context.registerPerspectives({
      binary: {
        PDF: {
          render: buildPdfDownload
        }
      }
    });
  6. Click Save.

Associating perspectives

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

  2. Go to the Template scripts tab and click Add scripts.

  3. Click the play button next to the perspective registered earlier with the jsreport validation script.

  4. From Download as… in the preview, click PDF.

If the integration is working, you can download a PDF, 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, see Scripting API documentation.