Gateway Scripting Errors

I am having some trouble with 2 gateway scripts that I have made for exporting a table to a CSV file, and printing a trend. They are being triggered by a tag change event. Both scripts work when I plug them into the scripting playground, but when I try and use them as gateway scripts I get the following error:

Scripting.TagChangeScriptManager Error executing tag change script: Lakeland/PQ2

Traceback (most recent call last):
File “TagChangeScript:Lakeland/PQ2”, line 1, in
AttributeError: ‘com.inductiveautomation.ignition.common.script.Scr’ object has no attribute ‘nav’

at org.python.core.PyException.fillInStackTrace(PyException.java:70)
at java.lang.Throwable.<init>(Throwable.java:181)
at java.lang.Exception.<init>(Unknown Source)
at java.lang.RuntimeException.<init>(Unknown Source)
at org.python.core.PyException.<init>(PyException.java:46)
at org.python.core.PyException.<init>(PyException.java:43)
at org.python.core.PyException.<init>(PyException.java:61)
at org.python.core.Py.AttributeError(Py.java:166)
at org.python.core.PyObject.noAttributeError(PyObject.java:930)
at org.python.core.PyObject.__getattr__(PyObject.java:925)
at org.python.pycode._pyx37.f$0(<TagChangeScript:Lakeland/PQ2>:6)
at org.python.pycode._pyx37.call_function(<TagChangeScript:Lakeland/PQ2>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1261)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:539)
at com.inductiveautomation.ignition.common.script.TagChangeScriptManager$TagChangeScriptHandler$Runner.run(TagChangeScriptManager.java:219)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Here is a copy of the gateway scripts:

system.nav.openWindow(“Advanced/PQ_2”)
window = system.gui.getWindow(“Advanced/PQ_2”)
data = window.rootContainer.getComponent(“Table”).data
new = system.dataset.toCSV(data, 1, 0)
filename = “C:\PQ\PQ.CSV”
system.file.writeFile(filename, new)

system.nav.openWindow(“Advanced/PQ”)
window = system.gui.getWindow(“Advanced/PQ”)
label = window.rootContainer.getComponent(“Easy Chart”)
job = system.print.createPrintJob(label)
job.showPrintDialog = 0
job.setMargins(0.5)
job.fitToPage = 1
job.orientation = system.print.LANDSCAPE
job.showPageFormat = 0
job.print()

What can I do to get these to work as Gateway scripts?

Dan

It looks like you are going to run into this problem because the Gateway Event Scripts are (for the most part) not user-interactive. I mean to say that they do not allow for opening windows and displaying or manipulating window components, such as with the system.gui functions.

Your best bet is to take the SQL script you have for your getComponent(“Table”).data and then use system.dataset.toDataSet to convert to the CSV file.

Let me know if I can help some more.

Here’s a brief example:

table = system.db.runQuery("SELECT * FROM Test")
ds = system.dataset.toDataSet(table)
new = system.dataset.toCSV(ds, 1, 0)
filename = "C:\PQ\PQ.CSV"
system.file.writeFile(filename, new)