Report API
Report API lets a script schedule and cancel the report definitions on the platform (classic + Jasper), export them to PDF / Excel files, or send them by email.
Report Status
Section titled “Report Status”ins.getReportStatus(reportName)
Section titled “ins.getReportStatus(reportName)”Returns a ReportStatus enum — two values:
| Value | Meaning |
|---|---|
"Scheduled" | Attached to the scheduler |
"Not Scheduled" | Not attached |
if (ins.getReportStatus("daily_energy_report") == "Not Scheduled") { ins.scheduleReport("daily_energy_report");}Schedule / Cancel
Section titled “Schedule / Cancel”ins.scheduleReport(reportName)
Section titled “ins.scheduleReport(reportName)”Adds a single report to the scheduler — it runs at the period in the report definition.
ins.scheduleReport("daily_energy_report");ins.cancelReport(reportName)
Section titled “ins.cancelReport(reportName)”Removes the report from the scheduler — remaining triggers are cancelled; a report currently being generated finishes normally.
ins.cancelReport("daily_energy_report");ins.scheduleReports() / ins.cancelReports()
Section titled “ins.scheduleReports() / ins.cancelReports()”Schedule or cancel every report definition in the project at once.
ins.scheduleReports();// ...ins.cancelReports();Email Delivery
Section titled “Email Delivery”ins.mailReport(reportName, startDate, endDate)
Section titled “ins.mailReport(reportName, startDate, endDate)”Generates a classic (non-Jasper) report for the given range and emails it to the recipients defined in the report.
var end = ins.now();var start = ins.getDate(end.getTime() - 86400000); // last 24 hoursins.mailReport("daily_energy_report", start, end);ins.mailJasperReport(reportName, params, usernames, subject, content)
Section titled “ins.mailJasperReport(reportName, params, usernames, subject, content)”Emails a Jasper report as a PDF attachment to the given users.
| Parameter | Type | Description |
|---|---|---|
reportName | String | Jasper report definition name |
params | Map<String, Object> | Parameters passed to the report |
usernames | String[] | Recipient platform usernames (emails resolved from profiles) |
subject | String | Email subject |
content | String | Email body |
var params = { "START_DATE": ins.getDate(ins.now().getTime() - 86400000), "END_DATE": ins.now(), "PROJECT_ID": 153};
ins.mailJasperReport( "energy_report", params, ["manager", "operator"], "Daily Energy Report", "The attached PDF report is generated automatically.");ins.mailJasperExcelReport(reportName, params, usernames, subject, content)
Section titled “ins.mailJasperExcelReport(reportName, params, usernames, subject, content)”Same signature — but attaches an Excel file instead of PDF.
ins.mailJasperExcelReport( "energy_report", params, ["manager"], "Daily Energy Report (Excel)", "The attached Excel report is generated automatically.");Export to File
Section titled “Export to File”ins.exportJasperPdfToFile(reportName, filePath)
Section titled “ins.exportJasperPdfToFile(reportName, filePath)”Writes a Jasper report as PDF to the platform’s file system.
ins.exportJasperPdfToFile("energy_report", "reports/daily_report.pdf");ins.exportJasperExcelToFile(reportName, filePath)
Section titled “ins.exportJasperExcelToFile(reportName, filePath)”Writes a Jasper report as Excel.
ins.exportJasperExcelToFile("energy_report", "reports/daily_report.xlsx");Example: Daily Automated Report
Section titled “Example: Daily Automated Report”Runs at 08:00 every day, writes yesterday’s report to a PDF file and emails it.
// Schedule Type: Daily, Time: 08:00function main() { var now = ins.now(); var y = ins.getDate(now.getTime() - 86400000);
var yyyy = 1900 + y.getYear(); var mm = ins.leftPad(String(y.getMonth() + 1), 2, "0"); var dd = ins.leftPad(String(y.getDate()), 2, "0"); var file = "reports/energy_" + yyyy + mm + dd + ".pdf";
ins.exportJasperPdfToFile("energy_report", file); ins.mailReport("energy_report", y, now); ins.writeLog("info", "Report", "Daily report generated: " + file);}main();