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

**URL:** <https://forum.inductiveautomation.com/t/cannot-coerce-value-named-query-path-into-type-interface-java-util-map/18042>\
**Category:** Ignition\
**Created:** [May 15, 2018, 3:55pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-named-query-path-into-type-interface-java-util-map/18042 "2018-05-15T15:55:48Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [May 15, 2018, 3:55pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-named-query-path-into-type-interface-java-util-map/18042/1 "2018-05-15T15:55:48Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 15, 2018, 4:01pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-named-query-path-into-type-interface-java-util-map/18042/2 "2018-05-15T16:01:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [May 15, 2018, 4:01pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-named-query-path-into-type-interface-java-util-map/18042/3 "2018-05-15T16:01:58Z")

</div>

The Gateway is version 7.9.6.

---

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [May 15, 2018, 4:10pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-named-query-path-into-type-interface-java-util-map/18042/4 "2018-05-15T16:10:00Z")

</div>

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:&nbsp;`actionPerformed`  
on component:&nbsp;`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

---

<div class="post-metadata">

**Author:** ![phillip.bow](https://avatars.discourse-cdn.com/v4/letter/p/ce73a5/32.png) [@phillip.bow](https://forum.inductiveautomation.com/u/phillip.bow)\
**Post date:** [May 15, 2018, 4:19pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-named-query-path-into-type-interface-java-util-map/18042/5 "2018-05-15T16:19:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [May 15, 2018, 4:20pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-named-query-path-into-type-interface-java-util-map/18042/6 "2018-05-15T16:20:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [May 15, 2018, 4:23pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-named-query-path-into-type-interface-java-util-map/18042/7 "2018-05-15T16:23:48Z")

</div>

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

THANKS!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 15, 2018, 6:07pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-named-query-path-into-type-interface-java-util-map/18042/8 "2018-05-15T18:07:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ammermanbrittanyf](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@ammermanbrittanyf](https://forum.inductiveautomation.com/u/ammermanbrittanyf)\
**Post date:** [June 24, 2019, 7:55pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-named-query-path-into-type-interface-java-util-map/18042/9 "2019-06-24T19:55:38Z")

</div>

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”?

---

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [June 24, 2019, 8:41pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-named-query-path-into-type-interface-java-util-map/18042/10 "2019-06-24T20:41:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 25, 2019, 12:02am UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-named-query-path-into-type-interface-java-util-map/18042/11 "2019-06-25T00:02:27Z")

</div>

> [@MikeAllgood](#):
>
> trying to access a named query inside of the project

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

---

<div class="post-metadata">

**Author:** ![MikeAllgood](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@MikeAllgood](https://forum.inductiveautomation.com/u/MikeAllgood)\
**Post date:** [June 25, 2019, 1:22pm UTC](https://forum.inductiveautomation.com/t/cannot-coerce-value-named-query-path-into-type-interface-java-util-map/18042/12 "2019-06-25T13:22:24Z")

</div>

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! 😊
