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

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

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

2 Likes

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

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

it worked. Thank you

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.

2 Likes

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

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

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

See posts like this:

Or just look for runNamedQuery in the v8 beta category.

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

1 Like

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.

3 Likes