Skip to content

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.

Returns a ReportStatus enum — two values:

ValueMeaning
"Scheduled"Attached to the scheduler
"Not Scheduled"Not attached
if (ins.getReportStatus("daily_energy_report") == "Not Scheduled") {
ins.scheduleReport("daily_energy_report");
}

Adds a single report to the scheduler — it runs at the period in the report definition.

ins.scheduleReport("daily_energy_report");

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();

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 hours
ins.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.

ParameterTypeDescription
reportNameStringJasper report definition name
paramsMap<String, Object>Parameters passed to the report
usernamesString[]Recipient platform usernames (emails resolved from profiles)
subjectStringEmail subject
contentStringEmail 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."
);

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");

Runs at 08:00 every day, writes yesterday’s report to a PDF file and emails it.

// Schedule Type: Daily, Time: 08:00
function 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();