# System.tag.write Not Triggering Value Changed Gateway Script

**URL:** <https://forum.inductiveautomation.com/t/system-tag-write-not-triggering-value-changed-gateway-script/11403>\
**Category:** Ignition\
**Created:** [March 22, 2016, 7:22pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-not-triggering-value-changed-gateway-script/11403 "2016-03-22T19:22:38Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [March 22, 2016, 7:22pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-not-triggering-value-changed-gateway-script/11403/1 "2016-03-22T19:22:38Z")

</div>

When system.tag.write is used to write new value to a UDT instance, the value changed gateway script never fires. However, on the next scan, the new value is contained in previousValue of the value changed script.

I would expect system.tag.write would trigger the value changed script with the new value as the currentValue.

/c

---

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [March 23, 2016, 12:41am UTC](https://forum.inductiveautomation.com/t/system-tag-write-not-triggering-value-changed-gateway-script/11403/2 "2016-03-23T00:41:16Z")

</div>

Message: Dispatching 0 change notifications and 1 write notifications.  
Time: Tue Mar 22 7:36:58PM  
Severity: DEBUG  
Logger: ignition.TagManager.Gateway

---

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [March 23, 2016, 12:50am UTC](https://forum.inductiveautomation.com/t/system-tag-write-not-triggering-value-changed-gateway-script/11403/3 "2016-03-23T00:50:53Z")

</div>

TRACE [TagManager-AWT-EventQueue-2] Subscribing to ‘MacLeanFogg/Context/Users/4756ADEC/PrinterId’, property: Value  
UserClass.getTag(‘PrinterId’) = ‘2112’  
UserClass.setTag(‘PrinterId’,‘jkhll’)  
DEBUG [Writes-AWT-EventQueue-2] Writing jkhll to “[default]MacLeanFogg/Context/Users/4756ADEC/PrinterId”  
TRACE [Writes-AWT-EventQueue-2] Write [default]MacLeanFogg/Context/Users/4756ADEC/PrinterId=jkhll pending. ID=6  
DEBUG [Writes-TagManager-thread-1] Received 1 write finished notification(s): [WriteOpDone[id=6, result=[GOOD]]]  
TRACE [Writes-TagManager-thread-1] Write 6 finished with result [GOOD]  
DEBUG [Gateway-TagManager-thread-1] Dispatching 0 change notifications and 1 write notifications.  
{‘current’: [2112, Good, Tue Mar 22 19:44:46 CDT 2016], ‘previous’: [jkhll, Good, Tue Mar 22 19:44:31 CDT 2016], ‘initial’: False, ‘tagPath’: u’[default]MacLeanFogg/Context/Users/4756ADEC/PrinterId’, ‘missedEvents’: False, ‘type’: ‘TAG\_CHANGE\_EVENT’}  
DEBUG [Gateway-TagManager-thread-1] Received 1 value changes: [MacLeanFogg/Context/Users/4756ADEC/PrinterId=[2112, Good, Tue Mar 22 19:44:46 CDT 2016]]

---

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [March 23, 2016, 12:05pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-not-triggering-value-changed-gateway-script/11403/4 "2016-03-23T12:05:43Z")

</div>

I forgot to mention that this is a SQL Query tag.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 23, 2016, 12:15pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-not-triggering-value-changed-gateway-script/11403/5 "2016-03-23T12:15:15Z")

</div>

[quote=“cmisztur2”]I forgot to mention that this is a SQL Query tag.[/quote]Well, there’s your problem. The SQL query is run at every scan and the tag change evaluated right after. So would an expression tag. Personally, I think it’s a design flaw that Ignition lets you write to such tags.

---

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [March 23, 2016, 2:35pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-not-triggering-value-changed-gateway-script/11403/6 "2016-03-23T14:35:59Z")

</div>

> [@pturmel](#):
>
> The SQL query is run at every scan and the tag change evaluated right after.

I created an expression tag on the Default 1000ms scan class and still am missing a change notification.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 23, 2016, 3:06pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-not-triggering-value-changed-gateway-script/11403/7 "2016-03-23T15:06:06Z")

</div>

You misunderstand my point. It’s not going to work and it’s not a bug. Ignition executes tags on a schedule determined by the scan class. For Query and Expression tags, it executes the query or expression, compares the result against the tag’s current value, and generates the tag change event if they differ. They will only generate tag change events right after they execute. These tags are not supposed to be written to. If there’s any bug, it’s Ignition letting you write to these tags at all. { Other than Client tags – they don’t have scan classes. }  
Why are you trying to do this? Anything you write will be replaced by the Query/Expression result at every scan.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 23, 2016, 3:38pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-not-triggering-value-changed-gateway-script/11403/8 "2016-03-23T15:38:03Z")

</div>

Phil is correct, you shouldn’t/can’t write to Expression/DB tags, and we _should_ be returning a bad quality instead of letting the write go through even though it basically has no effect.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 23, 2016, 3:50pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-not-triggering-value-changed-gateway-script/11403/9 "2016-03-23T15:50:57Z")

</div>

In cases like this, you must send your data to the point where the query/expression gets the data you want. In your case, I think you should be updating the database, not writing to this tag. Then the tag will follow on the next scan.

---

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [March 23, 2016, 5:45pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-not-triggering-value-changed-gateway-script/11403/10 "2016-03-23T17:45:35Z")

</div>

> [@pturmel](#):
>
> Why are you trying to do this?

I want writing the tag to execute a SQL update.

That's it.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 23, 2016, 8:28pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-not-triggering-value-changed-gateway-script/11403/11 "2016-03-23T20:28:03Z")

</div>

[quote=“cmisztur2”]I want writing the tag to execute a SQL update.[/quote]Ignition can’t automagically change a Select query into an Update statement. The script that writes the tag just needs to run an update query instead.

---

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [March 23, 2016, 9:08pm UTC](https://forum.inductiveautomation.com/t/system-tag-write-not-triggering-value-changed-gateway-script/11403/12 "2016-03-23T21:08:19Z")

</div>

Then this is a feature request for a SQL CRUD tag.
