# Using a tagpath variable inside of a button script

**URL:** <https://forum.inductiveautomation.com/t/using-a-tagpath-variable-inside-of-a-button-script/86199>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [February 22, 2024, 4:56pm UTC](https://forum.inductiveautomation.com/t/using-a-tagpath-variable-inside-of-a-button-script/86199 "2024-02-22T16:56:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan\_Golden1](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Jonathan\_Golden1](https://forum.inductiveautomation.com/u/Jonathan_Golden1)\
**Post date:** [February 22, 2024, 4:56pm UTC](https://forum.inductiveautomation.com/t/using-a-tagpath-variable-inside-of-a-button-script/86199/1 "2024-02-22T16:56:00Z")

</div>

I have created a dynamic "settings" popup window. I have succesfully used the {tagpath} variable function to select the proper A or B tag variant for all of the relevant data except for a "start" and "stop" button. When pressing the button I need the value of 14 to be written to the tag, but I need it to dynamically change the tag based upon the {tagpath} data. In scripting here is what I have...

```auto
selector = event.source.parent.tagpath
value = 14
system.tag.writeBlocking(['Compressor[selector]/Command'], [value])

```

I know this is something simple I'm just glossing over but can't get through my skull this morning.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [February 22, 2024, 5:00pm UTC](https://forum.inductiveautomation.com/t/using-a-tagpath-variable-inside-of-a-button-script/86199/2 "2024-02-22T17:00:40Z")

</div>

```auto
'Compressor[selector]/Command'

```

This is just a string. You will need to build the path, something like this:

```auto
'Compressor' + selector + '/Command'

```

And... welcome to the forum!!

---

<div class="post-metadata">

**Author:** ![Jonathan\_Golden1](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Jonathan\_Golden1](https://forum.inductiveautomation.com/u/Jonathan_Golden1)\
**Post date:** [February 22, 2024, 5:10pm UTC](https://forum.inductiveautomation.com/t/using-a-tagpath-variable-inside-of-a-button-script/86199/3 "2024-02-22T17:10:57Z")

</div>

I knew it was something I was just glossing over.

Thank you!
