Tag change not firing on initial event

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

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?

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

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

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

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

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

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

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

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

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.