# Tag change not firing on initial event

**URL:** <https://forum.inductiveautomation.com/t/tag-change-not-firing-on-initial-event/88692>\
**Category:** General Discussion\
**Tags:** ignition81\
**Created:** [April 11, 2024, 3:48pm UTC](https://forum.inductiveautomation.com/t/tag-change-not-firing-on-initial-event/88692 "2024-04-11T15:48:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [April 11, 2024, 3:48pm UTC](https://forum.inductiveautomation.com/t/tag-change-not-firing-on-initial-event/88692/1 "2024-04-11T15:48:44Z")

</div>

Within a UDT i have a expression tag (exprtag1) that takes 2 other tag values (value1, value2) expr = (value2-value1)\*.4

exprtag1 is set to Event Driven execution mode  
value1, value2 are OPCUA tags

there is a tag change script on exprtag1

```auto
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	if currentValue.quality.good: 
		system.tag.writeBlocking("[.]../Parameters.Deadband", currentValue.value)	

```

to write the value to a parameter.

Everything appears to be working except when tag is initially created.

When UDT instance is created the parameter value remains null even though exprtag1 = 0.4  
If I then change value1 or value2 the parameter gets updated.

why isn't this running on initialchange?

---

<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:** [April 11, 2024, 3:53pm UTC](https://forum.inductiveautomation.com/t/tag-change-not-firing-on-initial-event/88692/2 "2024-04-11T15:53:45Z")

</div>

Are you sure the quality is good on that initial change? You might be getting a quality change event after the UDT starts up.

---

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [April 11, 2024, 4:06pm UTC](https://forum.inductiveautomation.com/t/tag-change-not-firing-on-initial-event/88692/3 "2024-04-11T16:06:05Z")

</div>

shouldn't a quality change from bad --\> good also trigger the tag change

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

---

<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:** [April 11, 2024, 4:09pm UTC](https://forum.inductiveautomation.com/t/tag-change-not-firing-on-initial-event/88692/4 "2024-04-11T16:09:33Z")

</div>

Hmm. Not sure. Try logging everything before your quality check.

---

<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:** [April 11, 2024, 4:12pm UTC](https://forum.inductiveautomation.com/t/tag-change-not-firing-on-initial-event/88692/5 "2024-04-11T16:12:47Z")

</div>

BTW, `writeBlocking()` is not safe to use in a tag event, in most cases. Use `writeAsync()` instead.

---

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [April 11, 2024, 5:53pm UTC](https://forum.inductiveautomation.com/t/tag-change-not-firing-on-initial-event/88692/6 "2024-04-11T17:53:59Z")

</div>

```auto
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	logger = system.util.getLogger("myLogger")
	logger.info("TagChangeExecuted value="+str(currentValue.value)+'- tagPath='+str(tagPath))
	if currentValue.quality.good: 
		system.tag.writeAsync("[.]../Parameters.Deadband", currentValue.value)

```

Seems if I just do a few tags at a time it works fine. When my script adds a lot of tags at once it seems to randomly work and not work. I can't get consistent results.

Other similar set of tags I used this script

```auto
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	logger = system.util.getLogger("myLogger")
	logger.info("TagChangeExecuted"+str(currentValue.value))
	if currentValue.quality.good: 
		system.tag.writeAsync("[.]../Parameters.Deadband", currentValue.value)	

```

and I can see in the log where the tags are created

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

then later in log where they update with values and tag change runs again

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

but this time there are only 5 entries instead of 9. (However in this case all 9 executed the tag change and had the value of "8" updated.) However within the other set of tags I have seemingly random ones - delete all the tags and run the script to recreate them again and everything comes up correctly except differrent tags will have a null/default value for the parameter.deadband while others will be updated. Tag creation is by script command..system.tag.configure

---

<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:** [April 11, 2024, 5:59pm UTC](https://forum.inductiveautomation.com/t/tag-change-not-firing-on-initial-event/88692/7 "2024-04-11T17:59:56Z")

</div>

Keep in mind that these events will queue if you have many trying to run at once--the default tag event workqueue has only three threads. Something similar for expression tag execution. These are probably combining in pathological ways when you try to create many quickly.
