# Tag scripting problem

**URL:** <https://forum.inductiveautomation.com/t/tag-scripting-problem/63642>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [August 31, 2022, 3:25pm UTC](https://forum.inductiveautomation.com/t/tag-scripting-problem/63642 "2022-08-31T15:25:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![d.iannozzi](https://avatars.discourse-cdn.com/v4/letter/d/ecd19e/32.png) [@d.iannozzi](https://forum.inductiveautomation.com/u/d.iannozzi)\
**Post date:** [August 31, 2022, 3:25pm UTC](https://forum.inductiveautomation.com/t/tag-scripting-problem/63642/1 "2022-08-31T15:25:44Z")

</div>

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)  
 ![tag_script](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/2/e22d94a513559419602488849896cef0407e3b4b.png)
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  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/b/3bf09fe31d7c1f4f2f3f0e398bc2f7558b513b30.png)

Any help gratefully appreciated…

thanks and regards  
Dominic

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [August 31, 2022, 3:28pm UTC](https://forum.inductiveautomation.com/t/tag-scripting-problem/63642/2 "2022-08-31T15:28:39Z")

</div>

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](https://docs.inductiveautomation.com/display/DOC81/system.db.runNamedQuery)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/9/49cf23bfa28bb1227af73455ec427570437bf2f3.png)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 31, 2022, 3:32pm UTC](https://forum.inductiveautomation.com/t/tag-scripting-problem/63642/3 "2022-08-31T15:32:15Z")

</div>

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.

---

<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:** [August 31, 2022, 3:43pm UTC](https://forum.inductiveautomation.com/t/tag-scripting-problem/63642/4 "2022-08-31T15:43:53Z")

</div>

Also, this isn’t how you read or write to tags:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/b/6baad0a4fff2ff167ff5099970f49f92ce7333a3.png)

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

---

<div class="post-metadata">

**Author:** ![d.iannozzi](https://avatars.discourse-cdn.com/v4/letter/d/ecd19e/32.png) [@d.iannozzi](https://forum.inductiveautomation.com/u/d.iannozzi)\
**Post date:** [September 1, 2022, 12:53pm UTC](https://forum.inductiveautomation.com/t/tag-scripting-problem/63642/5 "2022-09-01T12:53:26Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/7/e7e15459396b63ac6b3dbc8af6cadecfda656263.png)  
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 ??  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/d/5ddfc97843ab65a19a0eec1cfff15a5fac7696cf.png)

thanks and regards,  
Dominic

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 1, 2022, 12:55pm UTC](https://forum.inductiveautomation.com/t/tag-scripting-problem/63642/6 "2022-09-01T12:55:31Z")

</div>

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

@paul-griffith has already addressed this in the post just above.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 1, 2022, 12:59pm UTC](https://forum.inductiveautomation.com/t/tag-scripting-problem/63642/7 "2022-09-01T12:59:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 1, 2022, 1:02pm UTC](https://forum.inductiveautomation.com/t/tag-scripting-problem/63642/8 "2022-09-01T13:02:48Z")

</div>

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