Named query scope

Using ignition 8.0.1 and running into an issue with named query.
I have a named query in Project1 and i am trying to run it from a script on a button in another project

When i run the script: system.db.runNamedQuery(“Project1”, “query name”, {"parameters’})
i get the error:“Java.lang.ClassCastException: java.lang.ClassCastException: Cannot coerce value ‘query name’ into type: interface java.util.Map”

and if i run it without the “Project1” name,system.db.runNamedQuery( “query name”, {"parameters’}) i get the error: “java.lang.Exception: java.lang.Exception”

From other posts it sounds like using the second approach should find the named query in whatever project it resides in but it doesn’t seem to be working that way.
Any Ideas?

You can only run named queries from other projects from gateway scope, where the project name parameter is required. I’ve argued that project name should be an optional parameter in all but gateway global scope…

1 Like

Ok, do you know of a workaround for this or would it be to just re-create the named query in each project that will run it?

Try using system.util.sendRequest() and have that project’s message handler run the query for you. You could even pass all relevant parameters to mimic calling runNamedQuery itself.

Phil’s option is good, or you can make a parent project for your queries and have all your other projects inherit from it. Then all your queries are available to all your child projects and you only have one set of queries to maintain.

I like this option but is it possible to add a parent project to existing projects or would they have to be re-created as a child from an existing parent?

At any point you can configure project properties on the gateway and select a project to inherit from.

Config > Projects > Edit for the project to which you’d like to add a parent project.

Adding a parent to a project which previously had no parent should be very safe as you are only introducing new resources to the child, and any overlapping resources will be overridden by the child.

REMOVING a parent project is where problems can occur, as there would be a high likelihood that you’re using resources inherited from the parent. Removal of those resources could result in bindings failing, Windows/Views/Pages no longer being found, and scripts no longer executing.

1 Like

Ok this makes sense. would there be any changes needed to add inheritance to a project that currently holds the scripts?
Im coming from an upgraded 7.9 structure so the stack would look like “Global --> project1 --> project2”
where project1 has the named query and project2 needs to run the query.

currently both project1 and project2 have global as a parent. Project1 has no users so it wouldn’t have to run as a client ever but it holds all original tag change scripts and transaction groups.

Okay, that’s a little bit of a loaded question, but let me try.

You don’t need to do anything to a project which will BE inherited.

The global > project1 > project2 setup is perfectly valid, but be aware of a few things:

  1. Neither global nor project1 will be runnable; only “leaf-node” projects are runnable. This means you should make sure that no users are reliant on project1 as a standalone project.
  2. Anything which project1 overrides from global will be overridden with project1’s resources inside of project2. Essentially, if I have a script in global, and I override it in project1, then project2 will use project1’s script, unless project2 elects to override with its own resource.
  3. If you have a behavior or resource which you handle differently between project1 and project2, you will now exclusively be using project2’s implementations.
1 Like

Currently both project1 and project2 should be inheriting from Global. Just move the query to global and you should be good.

1 Like

Ah yes this sounds like he simplest thing to do. Thanks for the help!

1 Like