"Cannot coerce value" Named Query Path "into type: interface java.util.Map

I have a script designed to build a list of parameters and then execute a named query. The script is a shared (Gateway) level script so the format of my system.db.runNamedQuery instruction is system.db.runNamedQuery(‘project name’, ‘named query path/name’, parameters). The error message I am getting is:

java.lang.ClassCastException: java.lang.ClassCastException: Cannot coerce value ‘TnT Queries/namedQ_InsertNewMCID’ into type: interface java.util.Map

The ‘TnT Queries/namedQ_InsertnewMCID’ named query is the correct path to the named query. The project name is setup correctly as well as the parameters.

I’m at a loss for why I’m getting this error.
Any ideas?
Thanks!

What Ignition version are you using, and can you copy the full details of the error message?

The Gateway is version 7.9.6.

Here are the error details:

11:07:37.205 [AWT-EventQueue-2] ERROR com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter - Error executing script for event: actionPerformed
on component: btnAdd.
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last):
File “event:actionPerformed”, line 13, in
File “module:shared.ContainerBatchAdd”, line 79, in batchAddContainer
at com.inductiveautomation.ignition.common.TypeUtilities.coerce(TypeUtilities.java:1292)

at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.coerce(PyArgumentMap.java:108)

at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.interpretPyArgs(PyArgumentMap.java:66)

at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.interpretPyArgs(PyArgumentMap.java:36)

at com.inductiveautomation.ignition.client.script.ClientDBUtilities.runNamedQuery(ClientDBUtilities.java:79)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

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

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

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

java.lang.ClassCastException: java.lang.ClassCastException: Cannot coerce value ‘TnT Queries/namedQ_InsertNewMCID’ into type: interface java.util.Map

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:429)
at org.python.core.PyObject.__call__(PyObject.java:422)
at org.python.core.PyObject.__call__(PyObject.java:426)
at org.python.pycode._pyx215.batchAddContainer$1(<module:shared.ContainerBatchAdd>:89)
at org.python.pycode._pyx215.call_function(<module:shared.ContainerBatchAdd>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyBaseCode.call(PyBaseCode.java:166)
at org.python.core.PyFunction.__call__(PyFunction.java:338)
at org.python.pycode._pyx151.f$0(<event:actionPerformed>:19)
at org.python.pycode._pyx151.call_function(<event:actionPerformed>)
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:1275)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:634)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:180)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:271)
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:57)
at com.sun.proxy.$Proxy28.actionPerformed(Unknown Source)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.focusLost(Unknown Source)
at java.awt.AWTEventMulticaster.focusLost(Unknown Source)
at java.awt.AWTEventMulticaster.focusLost(Unknown Source)
at java.awt.Component.processFocusEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.dispatchAndCatchException(Unknown Source)
at java.awt.KeyboardFocusManager.processCurrentLightweightRequests(Unknown Source)
at java.awt.KeyboardFocusManager$4.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Caused by: org.python.core.PyException: Traceback (most recent call last):
File “event:actionPerformed”, line 13, in
File “module:shared.ContainerBatchAdd”, line 79, in batchAddContainer
at com.inductiveautomation.ignition.common.TypeUtilities.coerce(TypeUtilities.java:1292)

at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.coerce(PyArgumentMap.java:108)

at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.interpretPyArgs(PyArgumentMap.java:66)

at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.interpretPyArgs(PyArgumentMap.java:36)

at com.inductiveautomation.ignition.client.script.ClientDBUtilities.runNamedQuery(ClientDBUtilities.java:79)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

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

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

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

java.lang.ClassCastException: java.lang.ClassCastException: Cannot coerce value ‘TnT Queries/namedQ_InsertNewMCID’ into type: interface java.util.Map

... 57 common frames omitted

Caused by: java.lang.ClassCastException: Cannot coerce value ‘TnT Queries/namedQ_InsertNewMCID’ into type: interface java.util.Map
at com.inductiveautomation.ignition.common.TypeUtilities.coerce(TypeUtilities.java:1292)
at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.coerce(PyArgumentMap.java:108)
at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.interpretPyArgs(PyArgumentMap.java:66)
at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.interpretPyArgs(PyArgumentMap.java:36)
at com.inductiveautomation.ignition.client.script.ClientDBUtilities.runNamedQuery(ClientDBUtilities.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.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)
… 54 common frames omitted

I believe, depending on how the shared script is called, it could execute in the Gateway scope or the Project scope.

If you’re calling it from a button it is executing in the Project scope so you can’t specify the project as a parameter.

2 Likes

I am using a button! I’ll remove the project name and give it a try!

That did it! I’ll need to remember this (not a trivial thing BTW).

THANKS!

1 Like

I wouldn’t call it “Project Scope”. In this case, it is “Client Scope”, which is always associated with one project.
The other two scopes are “Gateway Global Scope” and “Gateway Project Scope”. The latter is also associated with one project.

1 Like

I am having this same error now, so I appreciate your comments on this issue. But, what do you mean when you “remove the project name”?

If I recall correctly, and I’ve slept since then and have worked on a number of other projects, I was including the project name in my system.db.runNamedQuery instruction. That function has a couple of overridable methods. One uses the project name, system.db.runNamedQuery(project, path, parameters), (I assume this is to access named queries on another project on the same gateway). That apparently fails if you are trying to access a named query inside of the project (or the project the client is currently connected to) you are calling the function from.
Using the override method system.db.runNamedQuery(path, parameters) is what should be used from inside the project where the named query is defined.

Hope that helps,
Mike

To be more clear, the (path, parameters) argument list is required when in a client or designer -- the project is implied. The (project, path, parameters) argument list is required in the gateway, which may or may not be in project scope. IMNSHO, this deviation from the other system.db functions is an API flaw....

2 Likes

That was kind of my thought as well.
The way I was originally thinking about this was that if the project was called out, regardless of whether it was the project from whence the method was called or outside of it, it should have the wherewithal to locate and execute the named query. Alas I’m often proven wrong! :blush:

1 Like