Example of code and location for exporting to an excel sheet

I need an example of where, how and what sytax to use for sending my alert log to an excel file ever 24 hours at mid night.

I can make it create and send to excel by clicking a button with the code below in the event handler but I need it to be automatic at mid night.

 results = system.db.runQuery("SELECT * FROM alert_log")
 results = system.dataset.toDataSet(results)
 spreadsheet = system.dataset.dataSetToExcel(1, [results])
 filePath = "C:\\output\\results1.xls"
 system.file.writeFile(filePath, spreadsheet)

I’m new to Ignition and Java language. Please help! :cry:

You can create an Ignition Gateway Timer Event Script from the Project > Event Scripts Gateway > Timer menu item in the designer. The timer script will run every hour and it will look something like:from java.util import Date import system d = Date() if system.db.dateFormat(d, "HH") == "00": results = system.db.runQuery("SELECT * FROM alert_log") results = system.dataset.toDataSet(results) spreadsheet = system.dataset.dataSetToExcel(1, [results]) filePath = "C:\\output\\results1.xls" system.file.writeFile(filePath, spreadsheet)Of course it will save the results on the server machine. If you want that to happen on each client you can make Client Event Scripts.

[quote=“Travis.Cox”]You can create an Ignition Gateway Timer Event Script from the Project > Event Scripts Gateway > Timer menu item in the designer. The timer script will run every hour and it will look something like:from java.util import Date import system d = Date() if system.db.dateFormat(d, "HH") == "00": results = system.db.runQuery("SELECT * FROM alert_log") results = system.dataset.toDataSet(results) spreadsheet = system.dataset.dataSetToExcel(1, [results]) filePath = "C:\\output\\results1.xls" system.file.writeFile(filePath, spreadsheet)Of course it will save the results on the server machine. If you want that to happen on each client you can make Client Event Scripts.[/quote]

I might be advisable to make the filepath dynamic too.

filePath = "C:\\output\\results_%s.xls" % system.db.dateFormat(d, "yyyyMMdd")

Thanks! :prayer:

PS Any additional help to make this even better will be GREATLY appreciated!