# Run named query to write to different tag using event scripts. Keep getting error code. Help!

**URL:** <https://forum.inductiveautomation.com/t/run-named-query-to-write-to-different-tag-using-event-scripts-keep-getting-error-code-help/89671>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [April 29, 2024, 11:08pm UTC](https://forum.inductiveautomation.com/t/run-named-query-to-write-to-different-tag-using-event-scripts-keep-getting-error-code-help/89671 "2024-04-29T23:08:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeffrey\_Lerette](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@Jeffrey\_Lerette](https://forum.inductiveautomation.com/u/Jeffrey_Lerette)\
**Post date:** [April 29, 2024, 11:08pm UTC](https://forum.inductiveautomation.com/t/run-named-query-to-write-to-different-tag-using-event-scripts-keep-getting-error-code-help/89671/1 "2024-04-29T23:08:16Z")

</div>

This is my script I have on value change event scripting on one tag. When this tag changes I want to query SQL for a result and write that to a memory tag. I'm not great at python so please have mercy.

```
Val1 = "[default]AGM_Assembly/L_06_PTester/Serial_Modified"
Val2 = "[default]AGM_Assembly/L_06_PTester/Serial_SkuLine"
params = {"SerialNum" : Val1 , "LineCode" : Val2}
SQLRead = system.db.runNamedQuery("Fully_Integrated_Overview","ASSY/p_Test_Lookup", params)
system.tag.writeAsync("[default]AGM_Assembly/L_06_PTester/SQL_Value", SQLRead)

```

This is the error I am getting. Any help?

java.lang.ClassCastException: Error trying to coerce '[default]AGM\_Assembly/L\_06\_PTester/Serial\_Modified' to a number.

---

<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:** [April 29, 2024, 11:13pm UTC](https://forum.inductiveautomation.com/t/run-named-query-to-write-to-different-tag-using-event-scripts-keep-getting-error-code-help/89671/2 "2024-04-29T23:13:47Z")

</div>

You need to use `system.tag.readBlocking` to read tag values. What you've written is trying to pass the literal string "XXX/Serial\_Modified" as an integer value, rather than the _value of a tag by that name_.

> **[system.tag.readBlocking | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-readBlocking)**
>
> Reads the value of the tags at the given paths.

The most direct replacement for what you're trying to do would be:

```python
tagpaths = ["[default]AGM_Assembly/L_06_PTester/Serial_Modified", "[default]AGM_Assembly/L_06_PTester/Serial_SkuLine"]
qualifiedValues = system.tag.readBlocking(tagpaths)
Val1, Val2 = [qv.value for qv in qualifiedValues]
params = {"SerialNum" : Val1 , "LineCode" : Val2}
SQLRead = system.db.runNamedQuery("Fully_Integrated_Overview","ASSY/p_Test_Lookup", params)
system.tag.writeAsync("[default]AGM_Assembly/L_06_PTester/SQL_Value", SQLRead)

```

---

<div class="post-metadata">

**Author:** ![Jeffrey\_Lerette](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@Jeffrey\_Lerette](https://forum.inductiveautomation.com/u/Jeffrey_Lerette)\
**Post date:** [April 29, 2024, 11:38pm UTC](https://forum.inductiveautomation.com/t/run-named-query-to-write-to-different-tag-using-event-scripts-keep-getting-error-code-help/89671/3 "2024-04-29T23:38:27Z")

</div>

Thank you! I knew I was missing something simple!
