# Dynamically build source tag path for Reference Tag from other tag value

**URL:** <https://forum.inductiveautomation.com/t/dynamically-build-source-tag-path-for-reference-tag-from-other-tag-value/83724>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [January 3, 2024, 7:57am UTC](https://forum.inductiveautomation.com/t/dynamically-build-source-tag-path-for-reference-tag-from-other-tag-value/83724 "2024-01-03T07:57:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![manuele.longhi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/manuele.longhi/32/51470_2.png) [@manuele.longhi](https://forum.inductiveautomation.com/u/manuele.longhi)\
**Post date:** [January 3, 2024, 7:57am UTC](https://forum.inductiveautomation.com/t/dynamically-build-source-tag-path-for-reference-tag-from-other-tag-value/83724/1 "2024-01-03T07:57:56Z")

</div>

Hello all,  
Is there a way to dynamically build the source tag path of a Reference Tag?

I have a structure similar to the following:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/a/8a26636b0fadc974b4db3d7a30ba2a1d625a86bc.png)

(just pretend that the PLC tag is actually connected)  
What I'm trying to do is have the Temperature tag reference either the MEM/Temperature tag or the PLC/Temperature tag, based on the value of the Config tag: that is, if Config has value "MEM", I want Temperature to reference MEM/Temperature, whereas if Config has value "PLC", I want Temperature to reference PLC/Temperature instead.  
I can do that using an Expression tag, dynamically building the path I need by reading the Config tag. However, I also need to be able to write on the Temperature tag and have the value cascade back on the tag that is being referenced: that is, if I'm referencing the MEM/Temperature tag and I write the value 20 on the Temperature tag, I want the tag MEM/Temperature to also be written with the value 20.  
If I use an Expression tag, I lose the ability to write on the Temperature tag.

Is there any way I can solve this problem?  
Thanks

---

<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:** [January 3, 2024, 3:38pm UTC](https://forum.inductiveautomation.com/t/dynamically-build-source-tag-path-for-reference-tag-from-other-tag-value/83724/2 "2024-01-03T15:38:01Z")

</div>

I'm not sure what the application is here, but if you want to dynamically transfer data from `Temperature` to either `MEM/Temperature` or `PLC/Temperature`, I would use a [tag value change script](https://docs.inductiveautomation.com/display/DOC80/Tag+Event+Scripts) on `Temperature` that dynamically writes to either MEM or PLC, switching case based on the value of Config.

When `Temperature` changes, use [system.tag.readBlocking](https://docs.inductiveautomation.com/display/DOC81/system.tag.readBlocking?gclid=CjwKCAiAqNSsBhAvEiwAn_tmxapSzhswRjZqItgj3_USe8Q_NDBDcT9O5obN0ybMfXVjhCVJGrY6OBoCyJ0QAvD_BwE) to read the value of `Config` and, based on its value, use [system.tag.writeBlocking](https://docs.inductiveautomation.com/display/DOC80/system.tag.writeBlocking?gclid=CjwKCAiAqNSsBhAvEiwAn_tmxX2shoaNzX68SVW9AgNI3w5FdmNThPT53RxwIuS9q4iWm1gbAJxAHhoCjn8QAvD_BwE) to write to either MEM or PLC.

---

<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:** [January 3, 2024, 3:39pm UTC](https://forum.inductiveautomation.com/t/dynamically-build-source-tag-path-for-reference-tag-from-other-tag-value/83724/3 "2024-01-03T15:39:27Z")

</div>

Sounds like an XY problem. _ **Why** _ do you need this?

---

<div class="post-metadata">

**Author:** ![manuele.longhi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/manuele.longhi/32/51470_2.png) [@manuele.longhi](https://forum.inductiveautomation.com/u/manuele.longhi)\
**Post date:** [January 4, 2024, 7:05am UTC](https://forum.inductiveautomation.com/t/dynamically-build-source-tag-path-for-reference-tag-from-other-tag-value/83724/4 "2024-01-04T07:05:03Z")

</div>

Hi Alex, thanks for the suggestion. That would solve the problem of having to write back the value to either the MEM or PLC tag, however if I setup the Temperature tag as an expression (to mirror the value of either the MEM or PLC tag), I cannot write in the Temperature tag, meaning that the tag value change script would not trigger

---

<div class="post-metadata">

**Author:** ![manuele.longhi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/manuele.longhi/32/51470_2.png) [@manuele.longhi](https://forum.inductiveautomation.com/u/manuele.longhi)\
**Post date:** [January 4, 2024, 7:46am UTC](https://forum.inductiveautomation.com/t/dynamically-build-source-tag-path-for-reference-tag-from-other-tag-value/83724/5 "2024-01-04T07:46:20Z")

</div>

Hi pturmel,  
Yes I changed the problem a bit;

This is the whole problem I am trying to solve: we defined a UDT that looks like this

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

For each tag in the Data folder, we have

- a tag with the same name in the Config folder, which indicates where we want to read the data from
- a tag with the same name in the MEM folder, which is a memory tag
- a tag with the same name in the PLC folder, which is an OPC tag

We developed a Perspective interface that allows our client to create a new instance (or edit an existing one) of this UDT, specifying for each tag in the UDT

- Whether the tag is static (MEM) or read from the PLC
- The value of the tag (_if the tag is memory_)
- The address of the tag (_if it is PLC_)

This was done because the PLCs used by our client do not always have all the information that are required. Tags that are missing from the PLC are set as MEM, so that they can be manually edited by the operator if needed.

Since some of the tags in the Data folder need to be written, I need a way to be able to both read from either the MEM/PLC folders and write back to those tags.

Hope this is clear enough.

---

<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:** [January 4, 2024, 1:44pm UTC](https://forum.inductiveautomation.com/t/dynamically-build-source-tag-path-for-reference-tag-from-other-tag-value/83724/6 "2024-01-04T13:44:05Z")

</div>

You should make all your Data tags as OPC tags in the UDT. If a particular instance doesn't have one or more of them, **override** the `.valueSource` to "memory". (You can use a simple `system.tag.writeBlocking()` for that.)

No config required. No funky, unsupported expressions. Tag configuration bindings don't behave the same as other bindings, so your approach is broken. See this related topic:

> [@Tag folder ability to have parameters](https://forum.inductiveautomation.com/t/tag-folder-ability-to-have-parameters/83147/7):
>
> Of course it would be nice. If the implementation doesn't crush your gateway hardware. The fundamental difference between the configuration bindings in UDT members and the bindings in expression tags and query tags, is that the latter subscribe to changes in the tags they reference, when in event driven mode, so they can re-execute to stay up to date. General tag configuration bindings only execute at tag startup or restart, which is triggered by UDT parameter writes. Alarm configuration pr…

---

<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:** [January 4, 2024, 1:48pm UTC](https://forum.inductiveautomation.com/t/dynamically-build-source-tag-path-for-reference-tag-from-other-tag-value/83724/7 "2024-01-04T13:48:20Z")

</div>

Yep, this is the way I'd go about it. `writeBlocking()` is a very useful tool to have.
