# UDT Tag Value Change Event Script not executing

**URL:** <https://forum.inductiveautomation.com/t/udt-tag-value-change-event-script-not-executing/82052>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [November 17, 2023, 3:29pm UTC](https://forum.inductiveautomation.com/t/udt-tag-value-change-event-script-not-executing/82052 "2023-11-17T15:29:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_DeBate](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alex_debate/32/56483_2.png) [@Alex\_DeBate](https://forum.inductiveautomation.com/u/Alex_DeBate)\
**Post date:** [November 17, 2023, 3:29pm UTC](https://forum.inductiveautomation.com/t/udt-tag-value-change-event-script-not-executing/82052/1 "2023-11-17T15:29:11Z")

</div>

I have tag change scripts set up on some UDT members that are supposed to write to a specified tag outside of the UDT. However, they don't appear to be executing at all. I've set up a try/except clause that should write to a logger if the primary code block fails to execute, but even that isn't working. Here is the value change script:

```auto
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	try:
		if currentValue.quality == "Good" and currentValue.value == True:
			#	Writes the tag path of this tag to Last Alarm tag to help with troubleshooting
			message2 = tagPath.split("/")[2]+"."+tagPath.split("/")[5]+"."+tagPath.split("/")[7]
			system.tag.writeBlocking("[~]Derived Tags/Last Alarm", message2)
			
			alarm_num = tagPath.split("/")[-1]
			tagPath = "[.]../Strings/"+str(alarm_num)
			message = system.tag.readBlocking(tagPath)
			system.tag.writeBlocking("[~]Derived Tags/Last Alarm Cause", message)
	except:
		#Log tag change to info logger
		logger = system.util.getLogger("myLogger")
		logger.info("Alarm Bit Tag Change failed to write")

```

Any suggestions on what's failing here? I have 15 instances of this UDT and none of them are writing to either the tag or logger.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 17, 2023, 4:59pm UTC](https://forum.inductiveautomation.com/t/udt-tag-value-change-event-script-not-executing/82052/2 "2023-11-17T16:59:50Z")

</div>

> [@Alex\_DeBate](#):
>
> `currentValue.quality == "Good"`

This will never work - `quality` is a rich `QualityCode` object, and you're comparing it for equality against a string.

Try `if currentValue.quality.isGood()`.

---

<div class="post-metadata">

**Author:** ![mweber1](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@mweber1](https://forum.inductiveautomation.com/u/mweber1)\
**Post date:** [November 17, 2023, 5:00pm UTC](https://forum.inductiveautomation.com/t/udt-tag-value-change-event-script-not-executing/82052/3 "2023-11-17T17:00:36Z")

</div>

First, a couple of recommendations:

1. Create your logger outside of the try/except so you can use it throughout the script for various trace/debug purposes
2. give your logger a dynamic name so that you can pinpoint the logger to a specific instance e.g. `logger = system.util.getLogger(%s_logger % tagPath)`. This should make it a bit easier to troubleshoot specific instances
3. if possible, you should except specific errors (just as a general rule-of-thumb/good practice.
4. if your tag is a boolean, you can trim your if statement to

```auto
if currentValue.quality.isGood() and currentValue.value:

```

Second, my guess is that your script is working, but a qualified value's (what currentValue is) "quality" property is not a string. What you should use to detect whether the quality is good is `currentValue.quality.isGood()`.

also, note that `system.tag.writeBlocking` takes lists as its arguments, so you need to enclose your path and your value to write in square brackets `[]`.

Finally, I don't know that system.tag.writeBlocking throws any errors, so a try/except clause may not even be applicable here. It returns an error code, so you could do some debugging using that.

`if currentValue.quality.isGood() and currentValue.value:  
message2 = tagPath.split("/")[2] + tagPath.split("/"[5] + "."+tagPath.split("/")[7]  
system.tag.writeBlocking(["[~]Derived Tags/Last Alarm"], [message2])

alarm\_num tagPath.split("/")[-1]  
tagPath = "[.]../Strings/"+str(alarm\_num)  
message = system.tag.readBlocking([tagPath])[0]  
system.tag.writeBlocking(["[~]Derived Tags/Last Alarm Cause"], [message.value])`

from there, you can sprinkle in logger messages if needed.

Please let me know if you need any more guidance 🙂

[system.tag.writeBlocking Doc](https://docs.inductiveautomation.com/display/DOC81/system.tag.writeBlocking)

---

<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:** [November 17, 2023, 9:47pm UTC](https://forum.inductiveautomation.com/t/udt-tag-value-change-event-script-not-executing/82052/4 "2023-11-17T21:47:34Z")

</div>

> [@mweber1](#):
>
> system.util.getLogger(%s\_logger % tagPath)

Eww! Not _ **that** _ dynamic. Loggers are system resources that never go away once created. Including a project name and/or a script name is as far as I'd go with the dynamic logger name. Definitely not one per tag. If you really need more, consider using the SDK's `MDC` class to _temporarily_ add runtime attributes to specific log entries.
