# Update a property when a tag changes

**URL:** <https://forum.inductiveautomation.com/t/update-a-property-when-a-tag-changes/11874>\
**Category:** Ignition\
**Created:** [June 28, 2016, 8:55am UTC](https://forum.inductiveautomation.com/t/update-a-property-when-a-tag-changes/11874 "2016-06-28T08:55:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![eyudes](https://avatars.discourse-cdn.com/v4/letter/e/9fc29f/32.png) [@eyudes](https://forum.inductiveautomation.com/u/eyudes)\
**Post date:** [June 28, 2016, 8:55am UTC](https://forum.inductiveautomation.com/t/update-a-property-when-a-tag-changes/11874/1 "2016-06-28T08:55:37Z")

</div>

Hello everyone!

I have a template that show two labels depending on a value. If the value is 1, the label1 is shown and the other one is hidden, in contrast, when is 2, the label2 is shown and label1 is hidden. To do it, I am using the runScript function in the bindings in the labels’ visible property to read a bit of the tag.

That works but only when the window is shown at the first time, after that, if the value changes, nothing more happen. So, is there any way to update the value of the visible property to show or hid “online” depending on the tag value?.

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![abishur](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/abishur/32/9096_2.png) [@abishur](https://forum.inductiveautomation.com/u/abishur)\
**Post date:** [June 28, 2016, 3:05pm UTC](https://forum.inductiveautomation.com/t/update-a-property-when-a-tag-changes/11874/2 "2016-06-28T15:05:16Z")

</div>

If I’m understanding you correctly, you’re over complicating things 🙂

Click on the label you want to make visible, in the Property Editor Pane find the entry labeled “Visible” and click on the Binding icon.

Select the “Expression” Binding type and enter the expression to make the label visible when your tag or property is 1 for Label 1.

For example, assuming that Value is a custom property on your template

```auto
{Root Container.Value} = 1
```

Then repeat for label two and change it to

```auto
{Root Container.Value} = 2
```

---

<div class="post-metadata">

**Author:** ![eyudes](https://avatars.discourse-cdn.com/v4/letter/e/9fc29f/32.png) [@eyudes](https://forum.inductiveautomation.com/u/eyudes)\
**Post date:** [June 29, 2016, 10:52am UTC](https://forum.inductiveautomation.com/t/update-a-property-when-a-tag-changes/11874/3 "2016-06-29T10:52:33Z")

</div>

Thanks abushur.

It should be easy but it is taking me more time than I expected 😆 .

Your solution is the easiest, in my case, label 1 or 2 depend on a bit of a tag. To read specific bits in a tag, I am using a python function that return the value of a bit from a tag path. So, in order to evaluate the visible propertys I use an expression binding:

```auto
if(runScript("shared.utils.bitReadTag('"+{param1}+"/"+"ACT"+{param2}+"',1)") > 0,True,False)
```

If the code is correct (I think so because it works the first time), my function is returning the bit value and the if condition evaluates it. But only one time, when the window is loaded.

Any idea to solve it?

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![abishur](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/abishur/32/9096_2.png) [@abishur](https://forum.inductiveautomation.com/u/abishur)\
**Post date:** [June 29, 2016, 2:39pm UTC](https://forum.inductiveautomation.com/t/update-a-property-when-a-tag-changes/11874/4 "2016-06-29T14:39:24Z")

</div>

Ah, I see I’ve done something very similar to what you’re doing.

In my case, I broke it down into 2 separate parts.

First I created a custom variable (let’s just call it test for simplicity) that I used indirect tagging to get the variable of the integer I wanted to read i.e.

```auto
[{1}]/ACT{2}
```

Then I substituted the param1 custom property in for ref#1 and param2 for ref#2.

Then on the visible property I used the following code

```auto
if(getBit({Root Container.test},1),True,False)
```

This will make it visible whenever bit 1 is 1 and invisible when bit 1 is 0

(Side note, I know that’s not really what you’re asking for per se, but that’s as far as my knowledge takes me right now for a viable workaround, sorry)

---

<div class="post-metadata">

**Author:** ![abishur](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/abishur/32/9096_2.png) [@abishur](https://forum.inductiveautomation.com/u/abishur)\
**Post date:** [June 29, 2016, 3:22pm UTC](https://forum.inductiveautomation.com/t/update-a-property-when-a-tag-changes/11874/5 "2016-06-29T15:22:35Z")

</div>

Okay, I worked it out!

When using the runScript function you need to specify a poll rate in milliseconds otherwise it only executes once.

Modify your code like this and it should work

```auto
if(runScript("shared.utils.bitReadTag('"+{param1}+"/"+"ACT"+{param2}+"',1)",1000) > 0,True,False)
```

That assumes a 1 second poll rate

I tested it by creating a shared library named util and adding the following function to it

`def bitReadTag(tagToRead, bitLocation):
	rootValue = system.tag.read(tagToRead)
	bitValue= (rootValue.value >> bitLocation & 1)
	return bitValue`

and called it with this bit of code

```auto
if(runScript("shared.utils.bitReadTag('"+{Root Container.param1}+"/"+{Root Container.param2}+"',2)",1000),True,False)
```

(For my testing purposes Param1 was the tag folder name and param2 was the tag in the folder to read)

---

<div class="post-metadata">

**Author:** ![eyudes](https://avatars.discourse-cdn.com/v4/letter/e/9fc29f/32.png) [@eyudes](https://forum.inductiveautomation.com/u/eyudes)\
**Post date:** [June 30, 2016, 6:32am UTC](https://forum.inductiveautomation.com/t/update-a-property-when-a-tag-changes/11874/6 "2016-06-30T06:32:45Z")

</div>

> [@abishur](#):
>
> `if(runScript("shared.utils.bitReadTag('"+{param1}+"/"+"ACT"+{param2}+"',1)",1000) > 0,True,False)`

Superb! The key was the poll rate, using 1s as you said it works properly.

I find out lot of new things about Ignition every day! 😃

Thank you very much abishur ![:prayer:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e5a7e3b63facc151ea73e3b45db7bdb3d4bdc316.gif ":prayer:") ![:prayer:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e5a7e3b63facc151ea73e3b45db7bdb3d4bdc316.gif ":prayer:")

---

<div class="post-metadata">

**Author:** ![abishur](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/abishur/32/9096_2.png) [@abishur](https://forum.inductiveautomation.com/u/abishur)\
**Post date:** [June 30, 2016, 2:47pm UTC](https://forum.inductiveautomation.com/t/update-a-property-when-a-tag-changes/11874/7 "2016-06-30T14:47:17Z")

</div>

No problem, thank you for helping me learn about the runScript and shared libraries 😃
