# GatewayEvenScripting

**URL:** <https://forum.inductiveautomation.com/t/gatewayevenscripting/11524>\
**Category:** Ignition\
**Created:** [April 18, 2016, 3:32pm UTC](https://forum.inductiveautomation.com/t/gatewayevenscripting/11524 "2016-04-18T15:32:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [April 18, 2016, 3:32pm UTC](https://forum.inductiveautomation.com/t/gatewayevenscripting/11524/1 "2016-04-18T15:32:55Z")

</div>

Hi guys, right now I have a few Tag change event scripts being ran on the Gateway side the following is an example

```auto
from java.util import Calendar
cal = Calendar.getInstance()
value = system.tag.read("Press Lines/ChangeOver").value

if value == 1:
	Path = "Press Lines/DateOn"
	system.tag.write(Path, cal.getTime())

if value == 0:
	Path = "Press Lines/DateOff"
	system.tag.write(Path, cal.getTime())
```

Basically I’m grabbing a t\_stamp when the Boolean bit comes on and when it goes off. It works great my only issue is whenever I as anything new to the events or make a change that requires saving every even I have great ran again so most the time with since my Boolean is off the t\_stamp gets grabbed again which I don’t want to happen. I basically only want the script that i made change to or added to be ran. I assume I need to work with a tag value change function? Something like only run the script if the value of the Boolean has changed right?  
Can someone point me to the right direction? Thanks  
I’m using v 7.8.2

---

<div class="post-metadata">

**Author:** ![Curlyandshemp](https://avatars.discourse-cdn.com/v4/letter/c/bcef8e/32.png) [@Curlyandshemp](https://forum.inductiveautomation.com/u/Curlyandshemp)\
**Post date:** [April 20, 2016, 6:53pm UTC](https://forum.inductiveautomation.com/t/gatewayevenscripting/11524/2 "2016-04-20T18:53:56Z")

</div>

[quote=“Mr.K001”]Hi guys, right now I have a few Tag change event scripts being ran on the Gateway side the following is an example

```auto
from java.util import Calendar
cal = Calendar.getInstance()
value = system.tag.read("Press Lines/ChangeOver").value

if value == 1:
	Path = "Press Lines/DateOn"
	system.tag.write(Path, cal.getTime())

if value == 0:
	Path = "Press Lines/DateOff"
	system.tag.write(Path, cal.getTime())
```

Basically I’m grabbing a t\_stamp when the Boolean bit comes on and when it goes off. It works great my only issue is whenever I as anything new to the events or make a change that requires saving every even I have great ran again so most the time with since my Boolean is off the t\_stamp gets grabbed again which I don’t want to happen. I basically only want the script that i made change to or added to be ran. I assume I need to work with a tag value change function? Something like only run the script if the value of the Boolean has changed right?  
Can someone point me to the right direction? Thanks  
I’m using v 7.8.2[/quote]

work with the initialChange, if FALSE, then a project save did not trigger the tag script

[attachment=0]2016-04-20 14\_50\_33-192.168.11.10 - Remote Desktop Connection.png[/attachment]

---

<div class="post-metadata">

**Author:** ![diat150](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@diat150](https://forum.inductiveautomation.com/u/diat150)\
**Post date:** [April 20, 2016, 7:33pm UTC](https://forum.inductiveautomation.com/t/gatewayevenscripting/11524/3 "2016-04-20T19:33:56Z")

</div>

one issue I have found with gateway tag change scripts, at least in 7.8.1, is that if you use initial change and reboot the server or restart the ignition service, the first change wont be registered. maybe not a big deal, but in my case it was a report I was sending out every day. so if I reboot the server, the next day it wouldnt send. may not be an issue for you, but you may want to test this if it is something critical.

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [April 21, 2016, 4:27pm UTC](https://forum.inductiveautomation.com/t/gatewayevenscripting/11524/4 "2016-04-21T16:27:36Z")

</div>

> [@Curlyandshemp](#):
>
> work with the initialChange, if FALSE, then a project save did not trigger the tag script

That helped thank you. ended up going with:

```auto
if newValue.value == 1:
	if initialChange == 0:
            write to tag 1
if newValue.value == 0:
	if initialChange == 0:
            write to tag 2
```

seems to be working fine, I tried to add a new script event and save it and nothing changed also restarted the gateway server and nothing changed so I'm happy so far! ![:thumb_right:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/2026e28c0c425034352c1b75807edf956adc75f4.gif ":thumb\_right:")

> [@diat150](#):
>
> one issue I have found with gateway tag change scripts, at least in 7.8.1, is that if you use initial change and reboot the server or restart the ignition service, the first change wont be registered. maybe not a big deal, but in my case it was a report I was sending out every day. so if I reboot the server, the next day it wouldnt send. may not be an issue for you, but you may want to test this if it is something critical.

in this case this is fine with me, I don't want that first change after a server restart as it will show a wrong t\_stamp.  
why don't you set your reporting based on an actual time that way you don't have to worry about server restart?
