Checking entity compatibility
This document describes the usage of version 1 of Template scripts which is deprecated. For step-by-step instructions on how to create templates with version 2 see Templating and reporting. |
If you want to explicitly inform a user that a script will not work with a particular entity table or search you can throw an error from your script, for example:
async function fetchRecordData({ record, dataModelEntity }) {
const { DataRecord, DataModelEntity, Relation } = sirenapi;
// It's best to bail out early if the script is used with an unsupported data model entity.
const rootEntity = await dataModelEntity.getRoot();
if (await rootEntity.getLabel() !== 'Companies') {
throw new Error('This script only works with the Companies entity table.');
}
...
}
Next steps
-
To add asynchronous rendering to your script see asynchronous rendering.