API migration guides
Templates migration guide
Version 2 (Investigate 13.3.0)
To migrate a version 1 template script to version 2, follow these steps:
- 
Function context.registerTemplatehas been renamed. Search and replace it withcontext.registerPerspectives.
Migrate the recordView function
- 
Rename the registered recordViewfunction torenderand move it inside aview.<choose a view name>object.
- 
Move the data fetching logic to a function called enrichand keep only the rendering logic in functionrender. Whenenrichis defined Investigate calls therenderfunction periodically to update the view. Therenderfunction must not beasync.
- 
Store computed data inside input object computedData. Create a function calledinitialDatato initialize thecomputedDataobject with values beforeenrichis called.
Example
// Version 1
context.registerTemplate({
  async recordView(input) {
    const { render } = input;
    const recordData = { value: 'loading' };
    const timerId = setInterval(() => render(reactView(recordData)), 200);
    try {
      await fetchRecordData(input, recordData);
    } finally {
      clearInterval(timerId); // Clean up automatic updates before quitting
    }
    return reactView(recordData);
  }
});
// Version 2
context.registerPerspectives({
  view: {
    'My View': {
      initialData() {
        return { value: loading };
      },
      async enrich(input) {
        await fetchRecordData(input, input.computedData);
      },
      render({ computedData }) {
        return reactView(computedData);
      }
    }
  }
});Migrate download functions
- 
Rename registered object downloadtobinary.
- 
Replace calls to sirenapi.Reportingwith returning a binary output object.
Example
// Version 1
context.registerTemplate({
  download: {
    async pdf() {
      await sirenapi.Reporting.download(templateId, { value: 'value' }, 'report.pdf');
    },
    async txt() {
      await sirenapi.Reporting.downloadString('Report content here', 'report.txt');
    }
  }
});
// Version 2
context.registerPerspectives({
  binary: {
    'My pdf export': {
      render() {
        return { filename: 'report.pdf', templateId, data: { value: 'value' } };
      }
    },
    'My txt export': {
      render() {
        return { filename: 'report.txt', content: 'Report content here' };
      }
    }
  }
});