Edge perspective Alarm Journal export

Hi,

Can someone please help with exporting the Alarm Journal to an excel file, in a Perspective Edge project?

So far I’ve tried a script to a button but doesn’t work

def runAction(self, event):
    journal = system.alarm.queryJournal().getDataset()
    spreadsheet = system.dataset.toExcel(True, [journal])
    filePath = "C:\output\results.xlsx"
    system.file.writeFile(filePath, spreadsheet)

This function (probably) does not do what you think it does in a Perspective context. Perspective scripts are actually running on the gateway, so this will be attempting to write to a file on the C drive wherever the gateway is installed, not wherever your browser session is running.

You (probably) want the system.perspective.download function.

Much appreciated!

It works but it still pops and error with this in the Output Console: [AWT-EventQueue-0] ERROR com.inductiveautomation.ignition.client.util.gui.ErrorUtil -- Unable to run action 'dom.onClick' on Main Views/Alarm Journal@D/root/CoordinateContainer: code could not be compiled.
java.lang.Throwable: SyntaxError: no viable alternative at character '�??' (function:runAction, line 2)

Here’s my script now:

def runAction(self, event):
    journal = system.alarm.queryJournal().getDataset()
    spreadsheet = system.dataset.toExcel(True, [journal])
    system.perspective.download(filename="AlarmJournalExport.xlsx",  data=spreadsheet, contentType="application/vnd.ms-excel")