Create a template report
Generate a PDF from a Word or Excel template filled by a script, and run it manually, from a table operation or on a schedule.
A template report fills a Word or Excel template with data a script extracts, and produces a PDF. Create one when you need a formatted tabular document, such as a daily ticket summary or a record exported to a fixed layout.
Before you begin
- You need the
administratorrole. Only administrators see the template report menu items. - Prepare the Word or Excel template with placeholders for the data. The placeholder syntax is in Template report scripts.
- Query only the data the report needs, for example records created or closed in the last day, week or month. Large queries slow the report down.
Steps
-
Select Reporting → Reports → New template report.
-
Enter a Name and a Description. If the instance is multilingual (
system.multilingualis true), also fill in LocalizedName and LocalizedDescription, which are then used instead. -
Enter a Key. Table operations and scheduled reports refer to the template report by this key.
-
Attach the Word or Excel document to Template.
-
Write the Script that extracts the data and sets
answer. The script can read acontextobject to specialise the data. -
Save the template report, then run its table operation on the form to test it. Enter a context in the dialog, for example a table and a record ID, and run it.
-
Check the generated PDF. Adjust the script or the template until the output is right.
Variations
Run from a table operation
To export a record to the template from its form, create a client-side table operation on the record’s table. Its script builds the context and calls Navigate.viewTemplateReport with the template report’s key. See Table operations.
let context = { id: current.getID(), table: current.getTableName() };
Navigate.viewTemplateReport("ServicelyReport", context);
Run on a schedule
Add the template report to the Template reports field of a scheduled report. The scheduled report’s Context script supplies the context. See Schedule a report.
Result
Running the template report produces a PDF built from the template and the script’s data. From a table operation, the PDF opens for the current record. From a scheduled report, each recipient receives one PDF attachment per template report.