# Script runs multiple times on one trigger

**URL:** <https://forum.inductiveautomation.com/t/script-runs-multiple-times-on-one-trigger/2344>\
**Category:** Ignition\
**Created:** [November 15, 2010, 6:37pm UTC](https://forum.inductiveautomation.com/t/script-runs-multiple-times-on-one-trigger/2344 "2010-11-15T18:37:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![patrussell](https://avatars.discourse-cdn.com/v4/letter/p/848f3c/32.png) [@patrussell](https://forum.inductiveautomation.com/u/patrussell)\
**Post date:** [November 15, 2010, 6:37pm UTC](https://forum.inductiveautomation.com/t/script-runs-multiple-times-on-one-trigger/2344/1 "2010-11-15T18:37:06Z")

</div>

I have a script triggered by a property change event on a calendar object. When I select a date on the calendar the script will run multiple times, with different results. I am using this to set up a database selection in another object and need to ensure the script only runs one time to set up the parameters.

I have also tried attaching the script to the mouse click event but that did not seem to run at all.

Here is the script I am running:

[code]from java.util import Calendar  
cal = Calendar.getInstance()  
cal.add(Calendar.HOUR, -24)  
olddate = cal.getTime()

calen = event.source.parent.getComponent(“Calendar”)  
date = calen.date  
if date \< olddate:  
print “Archive”  
event.source.parent.getComponent(‘PassData’).Database = ‘L\_PROC\_DATA’  
event.source.parent.getComponent(‘PassData’).TableName = ‘COIL\_PROC\_SUMMARY’  
else:  
print “Active”  
event.source.parent.getComponent(‘PassData’).Database = ‘Tmill’  
event.source.parent.getComponent(‘PassData’).TableName = ‘RTM\_COIL\_HSIO\_SUM’[/code]

Any help would be greatly appreciated.

Pat Russell

---

<div class="post-metadata">

**Author:** ![Dravik](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@Dravik](https://forum.inductiveautomation.com/u/Dravik)\
**Post date:** [November 15, 2010, 7:32pm UTC](https://forum.inductiveautomation.com/t/script-runs-multiple-times-on-one-trigger/2344/2 "2010-11-15T19:32:37Z")

</div>

Um, I think you want to filter the property change.

maybe?

if event.propertyName == “calen.date”:

---

<div class="post-metadata">

**Author:** ![patrussell](https://avatars.discourse-cdn.com/v4/letter/p/848f3c/32.png) [@patrussell](https://forum.inductiveautomation.com/u/patrussell)\
**Post date:** [November 15, 2010, 7:39pm UTC](https://forum.inductiveautomation.com/t/script-runs-multiple-times-on-one-trigger/2344/3 "2010-11-15T19:39:35Z")

</div>

You are correct.

Added this line to the beginning of the script:

```auto
if event.propertyName == "Date":
```

I did manage to get it filtered so that the script only runs once but still have a problem with the if statement not evaluating properly.

Is there a better way to evaluate the time difference between two dates?

Pat

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [November 16, 2010, 7:04pm UTC](https://forum.inductiveautomation.com/t/script-runs-multiple-times-on-one-trigger/2344/4 "2010-11-16T19:04:52Z")

</div>

Dates aren’t directly comparable using the less-than operator ("\<"). Try using their time attribute, which is an 8-byte integer representing the time in UTC as milliseconds since Jan 1 1970 - it should provide reliable comparison.

i.e.

```auto
if date1.time < date2.time:
```

---

<div class="post-metadata">

**Author:** ![patrussell](https://avatars.discourse-cdn.com/v4/letter/p/848f3c/32.png) [@patrussell](https://forum.inductiveautomation.com/u/patrussell)\
**Post date:** [November 16, 2010, 8:13pm UTC](https://forum.inductiveautomation.com/t/script-runs-multiple-times-on-one-trigger/2344/5 "2010-11-16T20:13:22Z")

</div>

Thanks for the reply.

I worked with Michael from tech support late yesterday afternoon and we used the following solution:

[quote] olddate = system.db.dateFormat(olddate,“yyyyMMdd”)  
date = system.db.dateFormat(date,“yyyyMMdd”)  
dateDiff = int(date) - int(olddate)  
if dateDiff \< 0:  
[/quote]

It works like a charm!

Pat
