Add support for cancellation

A template script can take time to complete, so you should make sure it can be canceled when the user closes the Record Viewer or changes the record.

To support cancellation you should supply the cancelPromise input property to all the expensive queries of your script.

The following version of the script will pass cancelPromise to the getLinkedRecords query to allow Investigate to cancel it when required.

 * Common function for data fetching, used by all views/downloads.
async function fetchRecordData(input, recordData) {
  const { record, dataModelEntity, cancelPromise } = input;


  const investments = await record.getLinkedRecords(securedInvestmentsRelation, {
    size: 1000,
    orderBy: { field: 'raised_amount', order: 'desc' },
    cancelPromise // Pass the cancelPromise in the query options


Next steps

To see the full example code, see full example code.

To have your template script produce a downloadable report, see downloadable reports.