# Ignition Gateway Script

**URL:** <https://forum.inductiveautomation.com/t/ignition-gateway-script/80965>\
**Category:** Ignition\
**Created:** [October 25, 2023, 3:21pm UTC](https://forum.inductiveautomation.com/t/ignition-gateway-script/80965 "2023-10-25T15:21:37Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ly17](https://avatars.discourse-cdn.com/v4/letter/l/c57346/32.png) [@Ly17](https://forum.inductiveautomation.com/u/Ly17)\
**Post date:** [October 25, 2023, 3:21pm UTC](https://forum.inductiveautomation.com/t/ignition-gateway-script/80965/1 "2023-10-25T15:21:37Z")

</div>

Hi, I have a script in my project library called Table\_Config and defined a function which I called in the gateway events under tag change but nothing happens when tag changes.  
Here is my function script:

```auto
def updateTagBasedOnSelection(lineName, shiftNo, datasetPath, shiftVarPath):
	
	#Read the Shift Table & Shift Var
	datasetTag = system.tag.readBlocking(datasetPath)[0].value
	dataset = system.dataset.toDataSet(datasetTag)
	shiftV = system.tag.readBlocking(shiftVarPath)[0].value
	tagPathN = "[default]HHT Enterprise/LKC Plant/" + lineName + "/Production Shift " + str(shiftNo) + "/Hours/10 Hours"
	
	#Assign table values in column specified by shiftV to the 3rd column of the dataset tag.
	if shiftV != 0:
		for row in range(dataset.getRowCount()):
			valueN = dataset.getValueAt(row, shiftV)
			datasetTag = system.dataset.setValue(datasetTag, row, 2, valueN)
			system.tag.writeBlocking([tagPathN], [datasetTag])

```

When I test this in the Script Console, it works fine. I've tried to run this in the tag event change and in the property change for the input but nothing happens tag value changes.

Any thoughts on how to make this work? Thanks.

---

<div class="post-metadata">

**Author:** ![kyler.kamyszek](https://avatars.discourse-cdn.com/v4/letter/k/a4c791/32.png) [@kyler.kamyszek](https://forum.inductiveautomation.com/u/kyler.kamyszek)\
**Post date:** [October 25, 2023, 6:14pm UTC](https://forum.inductiveautomation.com/t/ignition-gateway-script/80965/2 "2023-10-25T18:14:41Z")

</div>

Can you post the script calling this function?

First thought might be the "[default]" in your tagPathN variable might have to be changed to the actual tag provider name or any tag path in the function input parameters.

---

<div class="post-metadata">

**Author:** ![Ly17](https://avatars.discourse-cdn.com/v4/letter/l/c57346/32.png) [@Ly17](https://forum.inductiveautomation.com/u/Ly17)\
**Post date:** [October 25, 2023, 6:23pm UTC](https://forum.inductiveautomation.com/t/ignition-gateway-script/80965/3 "2023-10-25T18:23:06Z")

</div>

Here is script for Gateway Tag Change.

```auto
if newValue.getValue() != previousValue.getValue() and not initialChange:
	lineName = 'Slimeline Area/Line 2'
	shiftNo = 1
	datasetPath = '[default]HHT Enterprise/LKC Plant/Slimeline Area/Line 2/Production Shift 1/Hours/10 Hours'
	shiftVarPath = '[default]HHT Enterprise/LKC Plant/Slimeline Area/Line 2/Production Shift 1/Hours/Shift Var'
	
	Table_Config.updateTagBasedOnSelection(lineName, shiftNo, datasetPath, shiftVarPath)

```

---

<div class="post-metadata">

**Author:** ![leonardo.godoi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/leonardo.godoi/32/27178_2.png) [@leonardo.godoi](https://forum.inductiveautomation.com/u/leonardo.godoi)\
**Post date:** [October 25, 2023, 6:32pm UTC](https://forum.inductiveautomation.com/t/ignition-gateway-script/80965/5 "2023-10-25T18:32:20Z")

</div>

Do you get any error messages under Status -\> Logs when the tag value changes and the script should be firing?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/c/cc4a90f70226134885b065322123c603c7a04ac0.png)

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [October 25, 2023, 6:40pm UTC](https://forum.inductiveautomation.com/t/ignition-gateway-script/80965/6 "2023-10-25T18:40:27Z")

</div>

In addition, throw in some logs, both to this function and to the calling function - do we know for sure it's running in the tag change event for instance.

---

<div class="post-metadata">

**Author:** ![Ly17](https://avatars.discourse-cdn.com/v4/letter/l/c57346/32.png) [@Ly17](https://forum.inductiveautomation.com/u/Ly17)\
**Post date:** [October 25, 2023, 6:42pm UTC](https://forum.inductiveautomation.com/t/ignition-gateway-script/80965/7 "2023-10-25T18:42:06Z")

</div>

I get an AuditManager warning

```auto
> com.inductiveautomation.ignition.gateway.web.util.LocalizedMessageException: Audit profile "Sample_Audit_Profile" not found.
> 
> at com.inductiveautomation.ignition.gateway.audit.AuditManagerImpl.getId(AuditManagerImpl.java:220)
> 
> at com.inductiveautomation.ignition.gateway.audit.AuditManagerImpl.getProfile(AuditManagerImpl.java:229)
> 
> at com.inductiveautomation.ignition.gateway.audit.AuditManagerImpl.getProfileForProject(AuditManagerImpl.java:255)
> 
> at com.inductiveautomation.ignition.gateway.servlets.gateway.functions.TagProviderRpc.audit(TagProviderRpc.java:310)
> 
> at com.inductiveautomation.ignition.gateway.servlets.gateway.functions.TagProviderRpc.write(TagProviderRpc.java:286)
> 
> at jdk.internal.reflect.GeneratedMethodAccessor84.invoke(Unknown Source)
> 
> at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> 
> at java.base/java.lang.reflect.Method.invoke(Unknown Source)
> 
> at com.inductiveautomation.ignition.gateway.servlets.gateway.AbstractGatewayFunction.invoke(AbstractGatewayFunction.java:228)
> 
> at com.inductiveautomation.ignition.gateway.servlets.Gateway.doPost(Gateway.java:434)
> 
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:523)
> 
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
> 
> at com.inductiveautomation.ignition.gateway.bootstrap.MapServlet.service(MapServlet.java:86)
> 
> at org.eclipse.jetty.servlet.ServletHolder$NotAsync.service(ServletHolder.java:1410)
> 
> at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
> 
> at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1665)
> 
> at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:527)
> 
> at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:131)
> 
> at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:578)
> 
> at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
> 
> at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:223)
> 
> at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1570)
> 
> at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
> 
> at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1384)
> 
> at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
> 
> at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:484)
> 
> at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1543)
> 
> at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
> 
> at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1306)
> 
> at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
> 
> at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
> 
> at com.inductiveautomation.catapult.handlers.RemoteHostNameLookupHandler.handle(RemoteHostNameLookupHandler.java:121)
> 
> at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
> 
> at org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:301)
> 
> at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:51)
> 
> at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:141)
> 
> at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
> 
> at org.eclipse.jetty.server.Server.handle(Server.java:563)
> 
> at org.eclipse.jetty.server.HttpChannel.lambda$handle$0(HttpChannel.java:505)
> 
> at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:762)
> 
> at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:497)
> 
> at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:282)
> 
> at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:314)
> 
> at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
> 
> at org.eclipse.jetty.io.ssl.SslConnection$DecryptedEndPoint.onFillable(SslConnection.java:558)
> 
> at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:379)
> 
> at org.eclipse.jetty.io.ssl.SslConnection$2.succeeded(SslConnection.java:146)
> 
> at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
> 
> at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
> 
> at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:416)
> 
> at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:385)
> 
> at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:272)
> 
> at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.lambda$new$0(AdaptiveExecutionStrategy.java:140)
> 
> at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:411)
> 
> at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:969)
> 
> at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1194)
> 
> at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1149)
> 
> at java.base/java.lang.Thread.run(Unknown Source)

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/7/97e3d1cf5850605e078b05232389e0b3bcc27c2c.png)

---

<div class="post-metadata">

**Author:** ![Ly17](https://avatars.discourse-cdn.com/v4/letter/l/c57346/32.png) [@Ly17](https://forum.inductiveautomation.com/u/Ly17)\
**Post date:** [October 25, 2023, 6:45pm UTC](https://forum.inductiveautomation.com/t/ignition-gateway-script/80965/8 "2023-10-25T18:45:58Z")

</div>

I don't have any logs in the scripts currently but I have tested them in the script console and it works.

---

<div class="post-metadata">

**Author:** ![Ly17](https://avatars.discourse-cdn.com/v4/letter/l/c57346/32.png) [@Ly17](https://forum.inductiveautomation.com/u/Ly17)\
**Post date:** [October 25, 2023, 6:49pm UTC](https://forum.inductiveautomation.com/t/ignition-gateway-script/80965/9 "2023-10-25T18:49:22Z")

</div>

Here is screenshot of tag event.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/0/b0b7c10e77e5976945b1786fbdc74e6e17664fef.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/9/59c7cd70266ef6a1d3c42af5265f15304614fe7e.png)

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [October 25, 2023, 7:15pm UTC](https://forum.inductiveautomation.com/t/ignition-gateway-script/80965/10 "2023-10-25T19:15:57Z")

</div>

I would recommend loggers anyways for production not just for testing for when stuff unexpectedly goes wrong and you need to look at what happened while you were not present.

Yes and you are probably calling it directly in the script console I am just suggesting loggers to make sure your gateway tag change is running as expected, because if the gateway tag change event is not triggering nothing will happen.

---

<div class="post-metadata">

**Author:** ![Ly17](https://avatars.discourse-cdn.com/v4/letter/l/c57346/32.png) [@Ly17](https://forum.inductiveautomation.com/u/Ly17)\
**Post date:** [October 25, 2023, 7:37pm UTC](https://forum.inductiveautomation.com/t/ignition-gateway-script/80965/11 "2023-10-25T19:37:44Z")

</div>

Agreed. We'll need add loggers.

Any thoughts on why this isn't working and how to resolve. I don't see any issues with the scripts. Thanks.

---

<div class="post-metadata">

**Author:** ![Ly17](https://avatars.discourse-cdn.com/v4/letter/l/c57346/32.png) [@Ly17](https://forum.inductiveautomation.com/u/Ly17)\
**Post date:** [October 25, 2023, 7:56pm UTC](https://forum.inductiveautomation.com/t/ignition-gateway-script/80965/12 "2023-10-25T19:56:27Z")

</div>

Here is the Gateway Script Log.

> com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 1, in AttributeError: 'NoneType' object has no attribute 'getValue'
> 
> at org.python.core.Py.AttributeError(Py.java:178)
> 
> at org.python.core.PyObject.noAttributeError(PyObject.java:965)
> 
> at org.python.core.PyObject. **getattr** (PyObject.java:959)
> 
> at org.python.pycode.\_pyx71.f$0(:7)
> 
> at org.python.pycode.\_pyx71.call\_function()
> 
> at org.python.core.PyTableCode.call(PyTableCode.java:173)
> 
> at org.python.core.PyCode.call(PyCode.java:18)
> 
> at org.python.core.Py.runCode(Py.java:1687)
> 
> at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:803)
> 
> at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runCode(ProjectScriptLifecycle.java:823)
> 
> at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:751)
> 
> at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runCode(ProjectScriptLifecycle.java:804)
> 
> at com.inductiveautomation.ignition.common.script.TagChangeScriptExecutor$TagChangeExecutionCallback.execute(TagChangeScriptExecutor.java:242)
> 
> at com.inductiveautomation.ignition.common.script.TagChangeScriptExecutor$TagChangeExecutionCallback.execute(TagChangeScriptExecutor.java:194)
> 
> at com.inductiveautomation.ignition.common.util.SerialExecutionQueue$PollAndExecute.run(SerialExecutionQueue.java:102)
> 
> at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
> 
> at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
> 
> at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
> 
> at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
> 
> at java.base/java.lang.Thread.run(Unknown Source)
> 
> Caused by: org.python.core.PyException: AttributeError: 'NoneType' object has no attribute 'getValue'

---

<div class="post-metadata">

**Author:** ![Ly17](https://avatars.discourse-cdn.com/v4/letter/l/c57346/32.png) [@Ly17](https://forum.inductiveautomation.com/u/Ly17)\
**Post date:** [October 25, 2023, 8:12pm UTC](https://forum.inductiveautomation.com/t/ignition-gateway-script/80965/13 "2023-10-25T20:12:56Z")

</div>

I think I resolved the previous error but got a new error message below.

> com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 7, in File "", line 7, in updateTagBasedOnSelection TypeError: toDataSet(): 1st arg can't be coerced to com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities$PyDataSet
> 
> at org.python.core.Py.TypeError(Py.java:236)
> 
> at org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:213)
> 
> at org.python.core.PyReflectedFunction.throwBadArgError(PyReflectedFunction.java:316)
> 
> at org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:325)
> 
> at org.python.core.PyReflectedFunction. **call** (PyReflectedFunction.java:171)
> 
> at org.python.core.PyReflectedFunction. **call** (PyReflectedFunction.java:208)
> 
> at org.python.core.PyObject. **call** (PyObject.java:461)
> 
> at org.python.core.PyObject. **call** (PyObject.java:465)
> 
> at org.python.pycode.\_pyx72.updateTagBasedOnSelection$1(:13)
> 
> at org.python.pycode.\_pyx72.call\_function()
> 
> at org.python.core.PyTableCode.call(PyTableCode.java:173)
> 
> at org.python.core.PyBaseCode.call(PyBaseCode.java:187)
> 
> at org.python.core.PyFunction. **call** (PyFunction.java:449)
> 
> at org.python.pycode.\_pyx71.f$0(:7)
> 
> at org.python.pycode.\_pyx71.call\_function()
> 
> at org.python.core.PyTableCode.call(PyTableCode.java:173)
> 
> at org.python.core.PyCode.call(PyCode.java:18)
> 
> at org.python.core.Py.runCode(Py.java:1687)
> 
> at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:803)
> 
> at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runCode(ProjectScriptLifecycle.java:823)
> 
> at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:751)
> 
> at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runCode(ProjectScriptLifecycle.java:804)
> 
> at com.inductiveautomation.ignition.common.script.TagChangeScriptExecutor$TagChangeExecutionCallback.execute(TagChangeScriptExecutor.java:242)
> 
> at com.inductiveautomation.ignition.common.script.TagChangeScriptExecutor$TagChangeExecutionCallback.execute(TagChangeScriptExecutor.java:194)
> 
> at com.inductiveautomation.ignition.common.util.SerialExecutionQueue$PollAndExecute.run(SerialExecutionQueue.java:102)
> 
> at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
> 
> at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
> 
> at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
> 
> at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
> 
> at java.base/java.lang.Thread.run(Unknown Source)
> 
> Caused by: org.python.core.PyException: TypeError: toDataSet(): 1st arg can't be coerced to com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities$PyDataSet
> 
> ... 30 common frames omitted

---

<div class="post-metadata">

**Author:** ![Ly17](https://avatars.discourse-cdn.com/v4/letter/l/c57346/32.png) [@Ly17](https://forum.inductiveautomation.com/u/Ly17)\
**Post date:** [October 25, 2023, 8:42pm UTC](https://forum.inductiveautomation.com/t/ignition-gateway-script/80965/14 "2023-10-25T20:42:42Z")

</div>

Finally got it resolved.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [October 26, 2023, 11:48am UTC](https://forum.inductiveautomation.com/t/ignition-gateway-script/80965/15 "2023-10-26T11:48:47Z")

</div>

Oh yea should have caught but you porbalby want to check `not initialChange` first so the conditional short-circuits and exits because if it is the initialChange there is no previousValue. Is that what you changed?
