Ignition Gateway Script

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:

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.

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.

1 Like

Here is script for Gateway Tag Change.

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)

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

1 Like

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.

I get an AuditManager warning

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

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

Here is screenshot of tag event.

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.

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.

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'

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

Finally got it resolved.

1 Like

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?