# Gateway Scripting Errors

**URL:** <https://forum.inductiveautomation.com/t/gateway-scripting-errors/8590>\
**Category:** Ignition\
**Created:** [June 19, 2014, 12:37pm UTC](https://forum.inductiveautomation.com/t/gateway-scripting-errors/8590 "2014-06-19T12:37:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dfenter](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@dfenter](https://forum.inductiveautomation.com/u/dfenter)\
**Post date:** [June 19, 2014, 12:37pm UTC](https://forum.inductiveautomation.com/t/gateway-scripting-errors/8590/1 "2014-06-19T12:37:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [June 19, 2014, 1:09pm UTC](https://forum.inductiveautomation.com/t/gateway-scripting-errors/8590/2 "2014-06-19T13:09:36Z")

</div>

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](http://inductiveautomation.com/support/usermanuals/ignition/system_dataset_todataset.htm) to convert to the CSV file.

Let me know if I can help some more.

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [June 19, 2014, 1:13pm UTC](https://forum.inductiveautomation.com/t/gateway-scripting-errors/8590/3 "2014-06-19T13:13:12Z")

</div>

Here’s a brief example:

```auto
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)
```
