# Property change is done several times

**URL:** <https://forum.inductiveautomation.com/t/property-change-is-done-several-times/16380>\
**Category:** Ignition\
**Tags:** ignition78\
**Created:** [December 20, 2017, 3:02pm UTC](https://forum.inductiveautomation.com/t/property-change-is-done-several-times/16380 "2017-12-20T15:02:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![francisco.romero](https://avatars.discourse-cdn.com/v4/letter/f/91b2a8/32.png) [@francisco.romero](https://forum.inductiveautomation.com/u/francisco.romero)\
**Post date:** [December 20, 2017, 3:02pm UTC](https://forum.inductiveautomation.com/t/property-change-is-done-several-times/16380/1 "2017-12-20T15:02:46Z")

</div>

Hi, I have a chart with code that changes a specific value on the table every time the data changes (propertyChange), but when I do this

if event.propertyName == “data”:  
ds = event.source  
val = 100 - ds.data.getValueAt(0,1)  
newData = system.dataset.setValue(ds.data, 0,0, val)  
ds.data = newData

the code is executed several times, is there a way to limit it to do it just one time?

Thanks!

---

<div class="post-metadata">

**Author:** ![martinel3746](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@martinel3746](https://forum.inductiveautomation.com/u/martinel3746)\
**Post date:** [December 20, 2017, 3:49pm UTC](https://forum.inductiveautomation.com/t/property-change-is-done-several-times/16380/2 "2017-12-20T15:49:17Z")

</div>

The last statement:  
 ds.data = newData  
invokes the “data” changed event - it has the potential of an endless loop.

Can you calculate the value along with the source of the data?  
Perhaps something like:  
SELECT 100 - column2, column2, column3, …

Some other options:  
Check the value and only update when needed.  
if event.propertyName == “data”:  
 ds = event.source  
 if ds.data.getValueAt(0,0) != 100 - ds.data.getValueAt(0,1):  
  #update the ds

Use a Custom Property to help control the updates.  
if event.propertyName == “data” and event.source.calcIsNeeded:  
 #update the ds  
The value of the calcIsNeeded could be done with system.util.invokeLater or some other external event so it’s not part of the data changing script.

---

<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:** [December 20, 2017, 6:34pm UTC](https://forum.inductiveautomation.com/t/property-change-is-done-several-times/16380/3 "2017-12-20T18:34:49Z")

</div>

Add a custom property to your table, and bind your original dataset to that new property. Then listen for changes to that property, make your adjustment to the dataset, and assign it to the unbound ‘data’ property.

---

<div class="post-metadata">

**Author:** ![francisco.romero](https://avatars.discourse-cdn.com/v4/letter/f/91b2a8/32.png) [@francisco.romero](https://forum.inductiveautomation.com/u/francisco.romero)\
**Post date:** [December 20, 2017, 6:59pm UTC](https://forum.inductiveautomation.com/t/property-change-is-done-several-times/16380/4 "2017-12-20T18:59:24Z")

</div>

Thank you ! I’ve never used the system.util.invokeLater but I will give it a try.

---

<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:** [December 20, 2017, 7:03pm UTC](https://forum.inductiveautomation.com/t/property-change-is-done-several-times/16380/5 "2017-12-20T19:03:56Z")

</div>

> [@francisco.romero](#):
>
> I've never used the system.util.invokeLater but I will give it a try.

No need. Your propertyChange event code should look like this:

```auto
if event.propertyName=='rawData':
    adjusted = 100 - event.newValue.getValueAt(0, 1)
    event.source.data = system.dataset.setValue(event.newValue, 0, 0, adjusted)

```
