Tag scripting problem

Hello everyone,
I am having a really hard time figuring this one out …hope someone can shed some light…

  1. I have a named Query called “Alarm_Query” connected to an SQL DB that simply returns a SELECT string …the query works fine
  2. I have setup an alarm on each tag in a user-defined UDT (F726xx_ExtFltxx)
  3. On the value change event of each tag I want to store the result string from the named query into the [.]…/AlmDspxxx tag of the UDT (the …/GP/G7261_FWTextxx is of type double and is the parameter I send in the query)
  4. I get the following error in the gateway

Any help gratefully appreciated…

thanks and regards
Dominic

If you run system.db.runNamedQuery in the gateway scope (which all tag change events are) you need to provide the project name. Look at the second example of the documentation - system.db.runNamedQuery - Ignition User Manual 8.1 - Ignition Documentation

2 Likes

That’s because tag change script execute in the gateway scope, so you need to use the gateway scope version of the runNamedQuery function. Its signature is system.db.runNamedQuery(project, path, parameters, [tx], [getKey])
You can see there that the first argument to the function needs to be a project, which is why it is looking for a project named Alarm_Query and not finding it.

1 Like

Also, this isn’t how you read or write to tags:
image

You need to use the system.tag.writeBlocking and system.tag.readBlocking functions.
https://docs.inductiveautomation.com/display/DOC81/system.tag

3 Likes

Hello Pascal,
I have updated the runNamedQuery function specifing the project and the gateway message error dispappeared.


I now have a coerce problem…the namedQuery parameter is set to float8 (which I saw is double) and this is the datatype for the tag in the UDT that I use as the parameter…what am I doing wrong ??

thanks and regards,
Dominic

That might be because of how you’re trying to update your tag’s value.

@PGriffith has already addressed this in the post just above.

2 Likes

Actually its your system.db.runNamedQuery that is giving this problem. After "Alarm_Query" it’s exepecting a dictionary of parameters (hence why it says it’s trying to coerce it to a java.util.Map). You pass params like {'someNamedQueryParam1':'someValue'}. Right now you are just passing the string "[.]../GP/G_FWText1".

However what @pascal.fragnoud said will also be an issue as well.

3 Likes

I’ll be honest: I didn’t even read the error message ;p

2 Likes