Property change is done several times

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 -,1)
newData = system.dataset.setValue(, 0,0, val) = newData

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


The last statement: = 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,0) != 100 -,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.

1 Like

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.

1 Like

Thank you ! 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:

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