# Named Queries in Value Changed Tag Event Scripts

**URL:** <https://forum.inductiveautomation.com/t/named-queries-in-value-changed-tag-event-scripts/28589>\
**Category:** Ignition\
**Created:** [September 26, 2019, 2:52pm UTC](https://forum.inductiveautomation.com/t/named-queries-in-value-changed-tag-event-scripts/28589 "2019-09-26T14:52:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerhard.louw](https://avatars.discourse-cdn.com/v4/letter/g/3ab097/32.png) [@gerhard.louw](https://forum.inductiveautomation.com/u/gerhard.louw)\
**Post date:** [September 26, 2019, 2:52pm UTC](https://forum.inductiveautomation.com/t/named-queries-in-value-changed-tag-event-scripts/28589/1 "2019-09-26T14:52:14Z")

</div>

Good day,

I am having difficulty in executing a Named Query in a Value Changed Tag Event Script.  
So this idea is that when my control step changes it populates a database for reporting.

When I test the name query it works perfectly.  
I have confirmed that all values in the Tag Event Script is read correctly.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/c51f78464a51341d78db393e79746cdcdaa0e9a5.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/c7e08db8516fe729406a8853c795871c99b5483c.png)

What am I missing here?

Regards,  
Gerhard

---

<div class="post-metadata">

**Author:** ![samngeru](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/samngeru/32/6007_2.png) [@samngeru](https://forum.inductiveautomation.com/u/samngeru)\
**Post date:** [October 1, 2019, 10:45pm UTC](https://forum.inductiveautomation.com/t/named-queries-in-value-changed-tag-event-scripts/28589/2 "2019-10-01T22:45:17Z")

</div>

You can try to explicitly define the variables within the runNamedQuery function. The system.db.runNamedQuery() function acts differently when it is called from a Global Scope as opposed to a client scope.

`system.db.runNamedQuery(project = "Lancewood_George", path = "StepLog1", parameters = params)`

---

<div class="post-metadata">

**Author:** ![sathianandan.dharmas](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sathianandan.dharmas](https://forum.inductiveautomation.com/u/sathianandan.dharmas)\
**Post date:** [April 23, 2021, 8:55pm UTC](https://forum.inductiveautomation.com/t/named-queries-in-value-changed-tag-event-scripts/28589/4 "2021-04-23T20:55:55Z")

</div>

@gerhard.louw Any luck? I’m trying to do the same thing but having a hard time getting it to the database. TIA

---

<div class="post-metadata">

**Author:** ![Shaheryar\_Ahmad](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@Shaheryar\_Ahmad](https://forum.inductiveautomation.com/u/Shaheryar_Ahmad)\
**Post date:** [May 22, 2022, 9:25am UTC](https://forum.inductiveautomation.com/t/named-queries-in-value-changed-tag-event-scripts/28589/5 "2022-05-22T09:25:47Z")

</div>

Any update about this?

I want to do the same, as run a Named Query “Insert” on a tag value when it changes to high.

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [May 22, 2022, 11:16pm UTC](https://forum.inductiveautomation.com/t/named-queries-in-value-changed-tag-event-scripts/28589/6 "2022-05-22T23:16:14Z")

</div>

Tag change events run in gateway scope, so you must include the project name, something like this:

```auto
params = {"val": 1}
system.db.runNamedQuery("ProjectName", "QueryName", params)

```

Also make sure your named query type is set to update, and check the gateway log if it doesn’t work, any error you find there will help track down the issue.
