# UDT tag Scripting

**URL:** <https://forum.inductiveautomation.com/t/udt-tag-scripting/78811>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [September 6, 2023, 12:57pm UTC](https://forum.inductiveautomation.com/t/udt-tag-scripting/78811 "2023-09-06T12:57:29Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 9, 2023, 4:19pm UTC](https://forum.inductiveautomation.com/t/udt-tag-scripting/78811/21 "2023-09-09T16:19:24Z")

</div>

`readBlocking` always returns a list of `QualifiedValues`.

`writeBlocking` will accept a `QualifiedValue`.

Probably also want to filter initialChange

---

<div class="post-metadata">

**Author:** ![zbinder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zbinder/32/28918_2.png) [@zbinder](https://forum.inductiveautomation.com/u/zbinder)\
**Post date:** [September 10, 2023, 8:03pm UTC](https://forum.inductiveautomation.com/t/udt-tag-scripting/78811/22 "2023-09-10T20:03:20Z")

</div>

Hmm, at this point I'd just throw out all assumptions and build this up slowly. Try one line of code that writes a static value to a full tag path. If that works, write it to an indirect tag path. If that works, add an if statement, etc. When a step doesn't work, you should have an idea of what's going wrong.

I'm wondering if the if statement is evaluating to false. Can't check that on my end, but I tried building a similar setup from the information I see here and it seems to be working fine.

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

This is the Value Changed script on ReadTag:

```auto
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	value = system.tag.readBlocking("[.]ReadTag")
	system.tag.writeBlocking("[.]Folder/WriteTag", value)

```

---

<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:** [September 11, 2023, 2:53am UTC](https://forum.inductiveautomation.com/t/udt-tag-scripting/78811/23 "2023-09-11T02:53:57Z")

</div>

`[~]` means "change tag's tag provider". To use relative referencing you should be using `[.]`

[https://docs.inductiveautomation.com/display/DOC81/Tag+Paths](https://docs.inductiveautomation.com/display/DOC81/Tag+Paths)

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

Edit: perhaps I missed that you'd already changed this...

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [September 11, 2023, 4:32pm UTC](https://forum.inductiveautomation.com/t/udt-tag-scripting/78811/24 "2023-09-11T16:32:03Z")

</div>

the only difference I see with what it it that I am using a tag external to the UDT where as yours is all internal the the UDT. I will try something like that.

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [September 11, 2023, 7:17pm UTC](https://forum.inductiveautomation.com/t/udt-tag-scripting/78811/25 "2023-09-11T19:17:03Z")

</div>

So I have found that if my IF or whatever I want to use is in the UDT it executes but if I use anything that exists outside of the UDT it doesnt execute. I can make that work, I think.

Thank for the help guys!

---

<div class="post-metadata">

**Author:** ![zbinder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zbinder/32/28918_2.png) [@zbinder](https://forum.inductiveautomation.com/u/zbinder)\
**Post date:** [September 11, 2023, 7:40pm UTC](https://forum.inductiveautomation.com/t/udt-tag-scripting/78811/26 "2023-09-11T19:40:27Z")

</div>

Glad you're making progress, though you should be able to reference outside tags if you want to.

I created an AlwaysTrue tag in the same root directory as the UDT instance and can access it no problem.

```auto
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	if system.tag.readBlocking("[.]../AlwaysTrue")[0].value:
		value = system.tag.readBlocking("[.]ReadTag")
		system.tag.writeBlocking("[.]Folder/WriteTag", value)

```

It also works when I use an absolute path.

```auto
	if system.tag.readBlocking("[Sample_Tags]AlwaysTrue")[0].value:

```

[Previous page](https://forum.inductiveautomation.com/t/udt-tag-scripting/78811.md?page=1)
