# Property Change Runs twice on only 1 change

**URL:** <https://forum.inductiveautomation.com/t/property-change-runs-twice-on-only-1-change/93558>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [July 22, 2024, 7:23pm UTC](https://forum.inductiveautomation.com/t/property-change-runs-twice-on-only-1-change/93558 "2024-07-22T19:23:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Randolph\_Sewell](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@Randolph\_Sewell](https://forum.inductiveautomation.com/u/Randolph_Sewell)\
**Post date:** [July 22, 2024, 7:23pm UTC](https://forum.inductiveautomation.com/t/property-change-runs-twice-on-only-1-change/93558/1 "2024-07-22T19:23:41Z")

</div>

I'm trying to run a script every single time a value is changed in a numeric entry field. I need this templatized and I will be running this script on all sorts of components like checkboxes and multi state buttons etc...

The issue: When making the template I would press play and test out the "property change" script by changing the numeric value, and that would write to a table once like intended (seen below). This worked great as you can see, but as soon as I put a instance of that template anywhere and change the value from the instance it logs twice. Is there a solution for this because it basically makes the propertyChange event handler useless in any template instances.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/7/2708cf157c9cc63237d32bf6d2b870aa7d9289b5.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/9/b9fcf66d200b5016e88da8ab232d3487b0548824.png)

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [July 22, 2024, 7:45pm UTC](https://forum.inductiveautomation.com/t/property-change-runs-twice-on-only-1-change/93558/2 "2024-07-22T19:45:51Z")

</div>

Does that query change the value in the field you are running the script on?  
if so that would cause a double run, due to the value changing after the query runs?

---

<div class="post-metadata">

**Author:** ![Randolph\_Sewell](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@Randolph\_Sewell](https://forum.inductiveautomation.com/u/Randolph_Sewell)\
**Post date:** [July 22, 2024, 7:52pm UTC](https://forum.inductiveautomation.com/t/property-change-runs-twice-on-only-1-change/93558/4 "2024-07-22T19:52:46Z")

</div>

I suppose I can just use a "prevVal" custom property on the window and maybe use a KeyPressed for the "enterkey" and check there and hope that only runs once? I feel like this is not the right way to do it though.

---

<div class="post-metadata">

**Author:** ![Randolph\_Sewell](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@Randolph\_Sewell](https://forum.inductiveautomation.com/u/Randolph_Sewell)\
**Post date:** [July 22, 2024, 7:55pm UTC](https://forum.inductiveautomation.com/t/property-change-runs-twice-on-only-1-change/93558/5 "2024-07-22T19:55:24Z")

</div>

No it just basically logs the previous value and the new value in a table and what time for a custom audit log which is why I really don't want it to show twice.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [July 22, 2024, 8:01pm UTC](https://forum.inductiveautomation.com/t/property-change-runs-twice-on-only-1-change/93558/6 "2024-07-22T20:01:24Z")

</div>

You can compare event.newValue and event.oldValue

`if event.propertyName == 'value' and event.oldValue <> event.newValue:`

---

<div class="post-metadata">

**Author:** ![Randolph\_Sewell](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@Randolph\_Sewell](https://forum.inductiveautomation.com/u/Randolph_Sewell)\
**Post date:** [July 22, 2024, 8:38pm UTC](https://forum.inductiveautomation.com/t/property-change-runs-twice-on-only-1-change/93558/7 "2024-07-22T20:38:12Z")

</div>

That won't work unfortunatly. The new and old value are different in both times it logs as seen in the picture :/.
