Referencing Parent UDT tag value in Child UDT

Hi all - long time listener, first time caller: I'm looking for a way to pass the value of a tag in my parent UDT to my child UDT, or to have my child UDT reference a tag value in its parent. It's straightforward to do if I was passing a parameter (just map the parent UDT parameter to the child UDT parameter), but the data I want to pass to the child is a STRING tag that might change from time to time and therefore doesn't make sense as a static parameter.

Think this (String 1 and UDT are elements of the Parent UDT, and String 2 is an element in the Child UDT)

Parent
____>String 1
____>UDT
________>String 2

What I would like to do is dynamically set the value of String 2 based on the value in String 1 (i.e. String 2 = String 1 + "Extra Text").

Is this even possible? I don't want to hard-code any reference to the parent tag into my child UDT definition, as I sometimes use that child UDT on its own.

Any help here would be greatly appreciated - even if it's a blunt "nope you're out of luck", as then I'd just abandon this and move on to something else.

Thanks!

Try using the built in logic builder buttons on the right when writing a tag expression. Your expression should like the image below.
String 2 tag needs to have "expression" value source.
ForumReply1

What about configuring a Value Changed script on the string in the parent UDT? It's probably not as reliable as a reference, and I'd be concerned about resources if it's changing often, but you did mention that it only changes from time to time.

How are you using this tag? Depending on your ultimate goal, it might be possible to combine String 1 and the extra text outside of the tag, like in an expression binding.

You could create String 2 more easily at the parent level, but it sounds like that doesn't quite meet what you're looking for.

Thanks DNice & zbinder. I'll get a bit more specific on my use case:

My parent tag is for a device, and the child tag holds alarm data for that device. I want to use the strings to generate a dynamic Display Path for an alarm (defined on a BOOL OPC tag within the child UDT) when it rings in. Originally I didn't use a child UDT at all for the alarm (just used a BOOL tag in the parent and an expression binding to set the display path), but I'm adding the ability to manipulate more elements of the alarm itself from the PLC (like priority, for instance) so it seemed to make more sense to create an alarm UDT than to bog down the parent UDT with a bunch of extra root tags.

For example, I have a UDT instance named "D1", with a memory string tag "Description" set to "Device 1". D1 has a child UDT called "Alarm", that contains a memory string tag "AlarmDescription". I would like to have D1/Alarm/AlarmDescription memory tag set to "Device 1 Alarm" (i.e. D1/Description + " Alarm"). But, if someone changed D1's "Description" tag to be "New Device 1", I'd like "AlarmDescription" to change to "New Device 1 Alarm".

I had hoped to just do this with an expression, but the child UDT instance can't see, to reference anything except parameters from its parent. I had tried to make a parameter within the child UDT and bind that parameter to the "Description" tag in the parent, but again it will only let me bind to a parameter and not a tag value.

As my Alarm UDT is used on its own sometimes (not always part of a parent UDT), I was hoping to define this relationship between parent and child when I create a new instance of the parent UDT.

Really just looking to see if a child UDT can reference the tag values (and not just the parameters) of its parent, or if the parent can push its own tag values (and not just parameters) to its children.

Not with bindings, no.

With value change scripts on the source value, sure.

1 Like

If it's just the display path you're worried about, you could make this work with some slight trade-offs.

image

image

image

Within the Parent UDT definition, you can override the child UDT's alarm tag's configured alarm with a Display Path of

{[.]../Description} + " " + {[.]Extra Text}

The downside is that you have to override the entire alarm configuration, so if you edit the child UDT you'll have to make sure the parent UDT's alarm configuration is still compatible. Alternatively, you could set it up through the child UDT, and you would just need to make sure that there's always a tag called "Description" in the same relative position (a folder should work just as well as a UDT).