# Help: Getting java.lang.ClassCastException in runNamedQuery on the script console

**URL:** <https://forum.inductiveautomation.com/t/help-getting-java-lang-classcastexception-in-runnamedquery-on-the-script-console/23789>\
**Category:** Ignition Early Access\
**Created:** [April 2, 2019, 3:42pm UTC](https://forum.inductiveautomation.com/t/help-getting-java-lang-classcastexception-in-runnamedquery-on-the-script-console/23789 "2019-04-02T15:42:59Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudipta.tripathy](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@sudipta.tripathy](https://forum.inductiveautomation.com/u/sudipta.tripathy)\
**Post date:** [April 2, 2019, 3:42pm UTC](https://forum.inductiveautomation.com/t/help-getting-java-lang-classcastexception-in-runnamedquery-on-the-script-console/23789/1 "2019-04-02T15:42:59Z")

</div>

Please help. Why am I getting this error on the script console?

data=system.db.runNamedQuery(“TestProject”,“GetAlert”, params)

java.lang.ClassCastException: java.lang.ClassCastException: Cannot coerce value ‘GetAlert’ into type: interface

---

<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:** [April 2, 2019, 3:51pm UTC](https://forum.inductiveautomation.com/t/help-getting-java-lang-classcastexception-in-runnamedquery-on-the-script-console/23789/2 "2019-04-02T15:51:00Z")

</div>

Omit “TestProject”. The designer is in project scope, so the project is inferred.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [April 2, 2019, 3:54pm UTC](https://forum.inductiveautomation.com/t/help-getting-java-lang-classcastexception-in-runnamedquery-on-the-script-console/23789/3 "2019-04-02T15:54:30Z")

</div>

@pturmel is correct - it’s attempting to cast “GetAlert” into a map of parameters.  
The final portion of that line is the big hint:

```auto
java.lang.ClassCastException: java.lang.ClassCastException: Cannot coerce value 'First' into type: interface java.util.Map

```

---

<div class="post-metadata">

**Author:** ![sudipta.tripathy](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@sudipta.tripathy](https://forum.inductiveautomation.com/u/sudipta.tripathy)\
**Post date:** [April 2, 2019, 3:54pm UTC](https://forum.inductiveautomation.com/t/help-getting-java-lang-classcastexception-in-runnamedquery-on-the-script-console/23789/4 "2019-04-02T15:54:33Z")

</div>

it worked. Thank you

---

<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:** [April 2, 2019, 4:12pm UTC](https://forum.inductiveautomation.com/t/help-getting-java-lang-classcastexception-in-runnamedquery-on-the-script-console/23789/5 "2019-04-02T16:12:39Z")

</div>

Just as an aside, I’m a bit disappointed that named queries introduced a scoping paradigm that’s different from the rest of Ignition. Elsewhere, like in the rest of the system.db collection of functions, there are three possible scopes: Gateway Global (old shared), Gateway Project, and Client/Designer Project. For those functions and any related operations, wherever a project default applies, including gateway project scope, it can be omitted. This is true whether the project scope is in the gateway or in the client. The named query functions break this behavior. This is rather egregious for Perspective, as its scripting is all Gateway Project scope.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 2, 2019, 5:24pm UTC](https://forum.inductiveautomation.com/t/help-getting-java-lang-classcastexception-in-runnamedquery-on-the-script-console/23789/6 "2019-04-02T17:24:21Z")

</div>

> [@pturmel](#):
>
> The named query functions break this behavior. This is rather egregious for Perspective, as its scripting is all Gateway Project scope.

What's broken? That you can't include the project param here?

---

<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:** [April 2, 2019, 5:27pm UTC](https://forum.inductiveautomation.com/t/help-getting-java-lang-classcastexception-in-runnamedquery-on-the-script-console/23789/7 "2019-04-02T17:27:22Z")

</div>

That you must include the project name in perspective scripts, even though you are in a project.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 2, 2019, 5:28pm UTC](https://forum.inductiveautomation.com/t/help-getting-java-lang-classcastexception-in-runnamedquery-on-the-script-console/23789/8 "2019-04-02T17:28:10Z")

</div>

Huh, I thought that wasn’t supposed to be true, can you give me an example?

---

<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:** [April 2, 2019, 5:33pm UTC](https://forum.inductiveautomation.com/t/help-getting-java-lang-classcastexception-in-runnamedquery-on-the-script-console/23789/9 "2019-04-02T17:33:49Z")

</div>

See posts like this:

> [@\[Bug-13088,13252\]Popup Views Fail To Interpret Parameters Which Are Objects Or Arrays](http://forum.inductiveautomation.com/t/bug-13088-13252-popup-views-fail-to-interpret-parameters-which-are-objects-or-arrays/23247/7):
>
> Yah, but my recommendation for passing the queryPath won’t work because we haven’t implemented a “property picker” for the queryPath input, so… You might just need to pass those two properties (project and queryPath), create a custom property (on the View, or Table Component) named whatever (“data” would be good though), bind the value of this new property to view.params.project, then use a script transform to run a named query where you also grab the value of self.view.params.queryPath. Somethi…

Or just look for runNamedQuery in the v8 beta category.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [April 2, 2019, 5:38pm UTC](https://forum.inductiveautomation.com/t/help-getting-java-lang-classcastexception-in-runnamedquery-on-the-script-console/23789/10 "2019-04-02T17:38:31Z")

</div>

> [@pturmel](#):
>
> For those functions and any related operations, wherever a project default applies, including gateway project scope, it can be omitted.

I think we have a ticket for that, it just hasn't percolated to the top yet.

---

<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:** [April 2, 2019, 5:43pm UTC](https://forum.inductiveautomation.com/t/help-getting-java-lang-classcastexception-in-runnamedquery-on-the-script-console/23789/11 "2019-04-02T17:43:18Z")

</div>

Consider making project the third parameter, never the first, and optional in all but gateway global scope. That would be consistent with other function signatures (like datasource names). It would also facilitate the future use of common named queries from other projects.
