Expression Tag calling a Named Query

I am using an expression tag who’s value is tied to the minute of the hour by “getMinute(now())”. Under the Tag Events/Value Changed I run a script that calls for a named query to push 3 data points to sequel. I can get this script to work on a button but it throws an error (listed below) when I run it on the expression tag. I’m at a loss for why it will work with a button script but not an expression tag.

com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 11, in valueChanged at com.inductiveautomation.ignition.gateway.script.GatewayDBUtilities.runNamedQuery(GatewayDBUtilities.java:354) at sun.reflect.GeneratedMethodAccessor129.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) java.lang.NullPointerException: java.lang.NullPointerException

at org.python.core.Py.JavaError(Py.java:495)

at org.python.core.Py.JavaError(Py.java:488)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)

at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.__call__(ScriptManager.java:431)

at org.python.core.PyObject.__call__(PyObject.java:404)

at org.python.core.PyObject.__call__(PyObject.java:408)

at org.python.pycode._pyx21.valueChanged$1(:13)

at org.python.pycode._pyx21.call_function()

at org.python.core.PyTableCode.call(PyTableCode.java:165)

at org.python.core.PyBaseCode.call(PyBaseCode.java:301)

at org.python.core.PyFunction.function___call__(PyFunction.java:376)

at org.python.core.PyFunction.__call__(PyFunction.java:371)

at org.python.core.PyFunction.__call__(PyFunction.java:361)

at org.python.core.PyFunction.__call__(PyFunction.java:356)

at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:649)

at com.inductiveautomation.ignition.common.sqltags.scripts.TagScriptManager$FunctionInvokerImpl.run(TagScriptManager.java:493)

at com.inductiveautomation.ignition.common.sqltags.scripts.AbstractTagScript.invoke(AbstractTagScript.java:33)

at com.inductiveautomation.ignition.common.sqltags.scripts.TagScriptManager$Task.invoke(TagScriptManager.java:442)

at com.inductiveautomation.ignition.common.sqltags.scripts.TagScriptManager$TagScriptDispatcher.run(TagScriptManager.java:405)

at com.inductiveautomation.ignition.common.execution.impl.BasicExecutionEngine$ThrowableCatchingRunnable.run(BasicExecutionEngine.java:518)

at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.util.concurrent.FutureTask.run(Unknown Source)

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Caused by: org.python.core.PyException: Traceback (most recent call last): File "", line 11, in valueChanged at com.inductiveautomation.ignition.gateway.script.GatewayDBUtilities.runNamedQuery(GatewayDBUtilities.java:354) at sun.reflect.GeneratedMethodAccessor129.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) java.lang.NullPointerException: java.lang.NullPointerException

... 27 common frames omitted

Caused by: java.lang.NullPointerException: null

at com.inductiveautomation.ignition.gateway.script.GatewayDBUtilities.runNamedQuery(GatewayDBUtilities.java:354)

at sun.reflect.GeneratedMethodAccessor129.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:186)

Here is the code I’m using.

#makes the value from the plc tag into a vacuum reading
	iPress = (system.tag.read("[~]RTO - SLC504/N37/N37:21").value *0.01)
	oPress = (system.tag.read("[~]RTO - SLC504/N37/N37:6").value *0.01)
	now = system.date.now()
	
	logger = system.util.getLogger("Reporting")
	logger.info("RTO data tranfering to SQL")
	
	#pushes data to SQL
	system.db.runNamedQuery("rto_sampleData", {"fanInlet":iPress, "fanOutlet":oPress, "datetime":now})
	
	logger.info("RTO data transfer complete")

When your running system.db.runNamedQuery() from a tag it is running from the gateway scope. Because of this you need to call out the project name that has your named query as part of it. The format you need is system.db.runNamedQuery(project, path, parameters).

3 Likes

It’s working now. Thank you!