# Question about Client Tag Change Script

**URL:** <https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756>\
**Category:** Ignition\
**Created:** [May 14, 2020, 6:30pm UTC](https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756 "2020-05-14T18:30:11Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![dustin.corban](https://avatars.discourse-cdn.com/v4/letter/d/85f322/32.png) [@dustin.corban](https://forum.inductiveautomation.com/u/dustin.corban)\
**Post date:** [May 14, 2020, 6:30pm UTC](https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756/1 "2020-05-14T18:30:11Z")

</div>

Hello again, sorry about all my questions. I was trying to find a way to say, “When Tag A = Value A then run this named query”. I was thinking i could do this with a client tag change script, but i have not written any scripts like this. I am mostly familiar with SQL syntax, so most of this is foreign to me. I am using Ignition 8.0 if that makes a difference as well.

---

<div class="post-metadata">

**Author:** ![kaushik.shah](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@kaushik.shah](https://forum.inductiveautomation.com/u/kaushik.shah)\
**Post date:** [May 14, 2020, 7:25pm UTC](https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756/2 "2020-05-14T19:25:54Z")

</div>

> [@dustin.corban](#):
>
> I was thinking i could do this with a client tag change script, but

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

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

If the Tag Events are disabled, create a tag and then go back and modify script.

---

<div class="post-metadata">

**Author:** ![dustin.corban](https://avatars.discourse-cdn.com/v4/letter/d/85f322/32.png) [@dustin.corban](https://forum.inductiveautomation.com/u/dustin.corban)\
**Post date:** [May 14, 2020, 7:53pm UTC](https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756/3 "2020-05-14T19:53:56Z")

</div>

Maybe i don’t fully understand what you are asking me to do here. Can we just pretend that i have no clue as what you mean by “modify script”. Maybe there is a different/better way to do this as well. I am open to any suggestions out there.

---

<div class="post-metadata">

**Author:** ![dustin.corban](https://avatars.discourse-cdn.com/v4/letter/d/85f322/32.png) [@dustin.corban](https://forum.inductiveautomation.com/u/dustin.corban)\
**Post date:** [May 14, 2020, 8:13pm UTC](https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756/4 "2020-05-14T20:13:24Z")

</div>

My named query is literally just an insert statement, that adds one row with a timestamp each time. There are no parameters. When my message display tag.value = 3 then execute insert statement into sql table.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 14, 2020, 9:18pm UTC](https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756/5 "2020-05-14T21:18:01Z")

</div>

That second screenshot is accessed from the tag’s properties under the Tag Events section, if that helps?

I definitely use this method to insert log entries into a table on a trigger, so @kaushik.shah’s method is appropriate. However I would use this as the condition to stop entries being inserted when the tag is reloaded:  
`if currentValue.value == 1 and not initialChange:` \*Edited from ‘initialValue’  
Considering you don’t need any parameters, just remove the parameter `dictionary` that kaushik.shah supplied in the function arguments.

An alternative would also be to do the same thing but use the gateway tag change event script area instead. It really depends on the circumstance: if my trigger tag is part of a udt, then I’ll use the tag’s change event handler; if it’s a standalone tag, I might use the gateway change event handler as it’s easier then to find your tag change scripts in the one place.

---

<div class="post-metadata">

**Author:** ![kaushik.shah](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@kaushik.shah](https://forum.inductiveautomation.com/u/kaushik.shah)\
**Post date:** [May 14, 2020, 9:41pm UTC](https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756/6 "2020-05-14T21:41:37Z")

</div>

Also,  
[https://docs.inductiveautomation.com/display/DOC80/Tag+Event+Scripts](https://docs.inductiveautomation.com/display/DOC80/Tag+Event+Scripts)

---

<div class="post-metadata">

**Author:** ![dustin.corban](https://avatars.discourse-cdn.com/v4/letter/d/85f322/32.png) [@dustin.corban](https://forum.inductiveautomation.com/u/dustin.corban)\
**Post date:** [May 15, 2020, 2:29pm UTC](https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756/7 "2020-05-15T14:29:08Z")

</div>

Here is what i have for the tag event script.

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

And my named query is this…

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

It does not appear to be working though. Did i make a mistake somewhere?

---

<div class="post-metadata">

**Author:** ![wking](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wking/32/21823_2.png) [@wking](https://forum.inductiveautomation.com/u/wking)\
**Post date:** [May 15, 2020, 3:09pm UTC](https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756/8 "2020-05-15T15:09:03Z")

</div>

You can’t have an insert statement and a select statement in a single named query.

I don’t see why you need it. As your use case goes. Cause your script isn’t doing anything with data returned.

But, if you were, you’d have to make two named queries…

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 15, 2020, 3:30pm UTC](https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756/9 "2020-05-15T15:30:19Z")

</div>

`initalValue` should be `initialChange`. Sorry, I was on my phone before I know I said initialValue. Also, what @wking said.  
You can check any script errors once it’s executed by going into the tag properties and going to the Diagnostics tab (in v8) or right click on the tag and go to Diagnostics (v7). Check the Events section

---

<div class="post-metadata">

**Author:** ![dustin.corban](https://avatars.discourse-cdn.com/v4/letter/d/85f322/32.png) [@dustin.corban](https://forum.inductiveautomation.com/u/dustin.corban)\
**Post date:** [May 18, 2020, 12:34pm UTC](https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756/11 "2020-05-18T12:34:34Z")

</div>

This is what i am getting in the diagnostics tab for this tag.

Error executing script.  
: Project name required for script execution: the Gateway Scripting Project is not set.

I tried  
…runNamedQuery(“ProjectName”“QueryName”)  
also  
…runNamedQuery(“ProjectName/QueryName”)

or does this mean something else?

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [May 18, 2020, 12:39pm UTC](https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756/12 "2020-05-18T12:39:30Z")

</div>

Examples shown at the bottom of this link:

[https://docs.inductiveautomation.com/display/DOC80/system.db.runNamedQuery](https://docs.inductiveautomation.com/display/DOC80/system.db.runNamedQuery)

---

<div class="post-metadata">

**Author:** ![dustin.corban](https://avatars.discourse-cdn.com/v4/letter/d/85f322/32.png) [@dustin.corban](https://forum.inductiveautomation.com/u/dustin.corban)\
**Post date:** [May 18, 2020, 12:55pm UTC](https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756/13 "2020-05-18T12:55:36Z")

</div>

I tried both of those examples. That is what i was referencing when i tried this. Since i do not have parameters, those were the only two options i saw. I am still getting the same message though. I was reading about the gateway scripting, and was not sure if i needed to enter my project name in there. I am testing it now.

---

<div class="post-metadata">

**Author:** ![dustin.corban](https://avatars.discourse-cdn.com/v4/letter/d/85f322/32.png) [@dustin.corban](https://forum.inductiveautomation.com/u/dustin.corban)\
**Post date:** [May 18, 2020, 12:57pm UTC](https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756/14 "2020-05-18T12:57:02Z")

</div>

Now i am getting, the sql statement did not return a result set. Which it wouldn’t correct, since it is an insert statement.

\*Note - it did still insert the row and information into the sql table though. Do i just ignore the current error and move on or should there be a step to fix it?

---

<div class="post-metadata">

**Author:** ![wking](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wking/32/21823_2.png) [@wking](https://forum.inductiveautomation.com/u/wking)\
**Post date:** [May 18, 2020, 2:05pm UTC](https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756/15 "2020-05-18T14:05:22Z")

</div>

@dustin.corban Did you remove the select statement from the named query?..

---

<div class="post-metadata">

**Author:** ![dustin.corban](https://avatars.discourse-cdn.com/v4/letter/d/85f322/32.png) [@dustin.corban](https://forum.inductiveautomation.com/u/dustin.corban)\
**Post date:** [May 18, 2020, 2:05pm UTC](https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756/16 "2020-05-18T14:05:54Z")

</div>

Yes I did.

---

<div class="post-metadata">

**Author:** ![wking](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wking/32/21823_2.png) [@wking](https://forum.inductiveautomation.com/u/wking)\
**Post date:** [May 18, 2020, 2:07pm UTC](https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756/17 "2020-05-18T14:07:31Z")

</div>

![query](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/83ea675cb3c7d6d5abb8d59804c1fccadb0faa4a.jpeg)

Did you select an update query from this dropdown?

---

<div class="post-metadata">

**Author:** ![dustin.corban](https://avatars.discourse-cdn.com/v4/letter/d/85f322/32.png) [@dustin.corban](https://forum.inductiveautomation.com/u/dustin.corban)\
**Post date:** [May 18, 2020, 2:08pm UTC](https://forum.inductiveautomation.com/t/question-about-client-tag-change-script/34756/18 "2020-05-18T14:08:38Z")

</div>

Nope. Sure didn’t. I thought that would just be used for an update query, not an insert. That fixed it. Thank you.
