# Gateway event script not triggering on tag change

**URL:** <https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-on-tag-change/57005>\
**Category:** Ignition\
**Created:** [March 9, 2022, 9:11am UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-on-tag-change/57005 "2022-03-09T09:11:58Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![SBL\_MC](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sbl_mc/32/56813_2.png) [@SBL\_MC](https://forum.inductiveautomation.com/u/SBL_MC)\
**Post date:** [March 9, 2022, 9:11am UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-on-tag-change/57005/1 "2022-03-09T09:11:58Z")

</div>

Hi,

LogCycle is increased +1 many times a day. Each time a script should trigger. If I open the gateway script interface, does nothing and saves the script it starts working again for the rest of the day. Nothing in the logs, gateway script status says success and triggered 2 days ago.

Version 8.1.14 and now updated to 8.1.15, still the same.

 ![trigger](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/f/cf47ca8f29c026109ed0d65a7202e3f89e537d06.png)

A normal day, yellow spikes are trigger events so its many times a day, all days of the week

 ![triggerlog](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/8/6841d15851b38099b2fd608799d149412aacc5cf.png)

---

<div class="post-metadata">

**Author:** ![SBL\_MC](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sbl_mc/32/56813_2.png) [@SBL\_MC](https://forum.inductiveautomation.com/u/SBL_MC)\
**Post date:** [March 9, 2022, 9:18am UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-on-tag-change/57005/2 "2022-03-09T09:18:39Z")

</div>

Additional info,

The last time I fixed it was Thursday last week, open, save and it works again. I see it stopped the same day we did upgrade to 8.1.15, is this a known issue? Do we need to open and close the gateway event dialog after any update?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 9, 2022, 1:04pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-on-tag-change/57005/3 "2022-03-09T13:04:50Z")

</div>

Get a thread dump next time you notice it has stopped.

---

<div class="post-metadata">

**Author:** ![SBL\_MC](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sbl_mc/32/56813_2.png) [@SBL\_MC](https://forum.inductiveautomation.com/u/SBL_MC)\
**Post date:** [March 9, 2022, 1:14pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-on-tag-change/57005/4 "2022-03-09T13:14:26Z")

</div>

That I can do.

---

<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:** [March 9, 2022, 1:33pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-on-tag-change/57005/5 "2022-03-09T13:33:46Z")

</div>

Add logging to the event that shows when it starts, at various points within, and then finishes. So you can catch when it doesn’t finish and approximately how far it got before hanging.

(Gateway event scripts for a specific event will not run in parallel–each must finish before the next event will run.)

---

<div class="post-metadata">

**Author:** ![SBL\_MC](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sbl_mc/32/56813_2.png) [@SBL\_MC](https://forum.inductiveautomation.com/u/SBL_MC)\
**Post date:** [March 10, 2022, 1:46pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-on-tag-change/57005/6 "2022-03-10T13:46:35Z")

</div>

It stopped again, 21 hours ago.

I don’t know how much the thread dump is worth now, so many hours after.  
There is 3 gateway-tags-eventscripts is in state Waiting.

 ![tagchange](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/e/ee98a609330589c6a7197f09fef571030ea9e456.png)

As you see it takes almost a second to run the script. The trigger is a counter in the PLC, when a new cycle has been registered it inc by one, another int tag containing bits representing what trigger is also set.

The script reads 500 OPC UA items and stores them in the SQL server, and set trigger to zero. This is not done, so something in the script obviously fails.

It was working so fine a few weeks back… from the programmer excuse book. I will add a “try” in my script, and an exception that reset the trigger.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 10, 2022, 1:48pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-on-tag-change/57005/7 "2022-03-10T13:48:12Z")

</div>

Can you upload the thread dump?

---

<div class="post-metadata">

**Author:** ![SBL\_MC](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sbl_mc/32/56813_2.png) [@SBL\_MC](https://forum.inductiveautomation.com/u/SBL_MC)\
**Post date:** [March 10, 2022, 1:58pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-on-tag-change/57005/8 "2022-03-10T13:58:08Z")

</div>

I PM’ed you a link 🙂

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 10, 2022, 2:09pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-on-tag-change/57005/9 "2022-03-10T14:09:16Z")

</div>

Hmm, I do not see the corresponding thread at all. Those 3 you saw “WAITING” are for tag event scripts, not gateway tag change scripts.

This thread would have a name like `gateway-tagchangescripts-project[$PROJECT]`.

I don’t see it at all, which is strange. If your logs go back far enough to when the execution stopped you can search for something like “Uncaught Throwable during execution” and see if you find anything.

---

<div class="post-metadata">

**Author:** ![SBL\_MC](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sbl_mc/32/56813_2.png) [@SBL\_MC](https://forum.inductiveautomation.com/u/SBL_MC)\
**Post date:** [March 10, 2022, 2:13pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-on-tag-change/57005/10 "2022-03-10T14:13:30Z")

</div>

Uncaught throwable, I find some but they are 3 days old and perspective-related.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 10, 2022, 2:16pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-on-tag-change/57005/11 "2022-03-10T14:16:28Z")

</div>

Hmm. Strange. I’d move forward with some logging before, during, and after, as well as adding a big `try`/`except` around the whole thing and printing any errors just in case.

It looks like the thread being absent might just mean the script hasn’t executed in a long enough time that the cached thread pool let it go, and that makes sense considering you said it hasn’t executed in 21 hours.

Another interesting thing might be to add a 2nd gateway tag change script for the same tag that does nothing but print a log message with the tag value and announce that it ran.

---

<div class="post-metadata">

**Author:** ![SBL\_MC](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sbl_mc/32/56813_2.png) [@SBL\_MC](https://forum.inductiveautomation.com/u/SBL_MC)\
**Post date:** [March 10, 2022, 2:20pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-on-tag-change/57005/12 "2022-03-10T14:20:11Z")

</div>

I added a big `try` / `except` as suggested. Will add logging to see if I can find what stops it.

Thanks for the follow up guys!

---

<div class="post-metadata">

**Author:** ![SBL\_MC](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sbl_mc/32/56813_2.png) [@SBL\_MC](https://forum.inductiveautomation.com/u/SBL_MC)\
**Post date:** [March 24, 2022, 7:38am UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-on-tag-change/57005/13 "2022-03-24T07:38:02Z")

</div>

I discovered it has stopped again. The log says it passed the script without issues, the reset trigger is the last function in the try part. The except only resets the trigger and log "Sequence failed".

I think I can conclude with that the script runs but there is some timing issues between Ignition and the PLC leaving the triggers hang.

> system.tag.write([p\_xxxx]xxxx\_ChemCont/triggerCount,0)
> 
> logger = system.util.getLogger(xxxx newCycle)  
> logger.info(Reset trigger)

---

<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:** [March 24, 2022, 11:36am UTC](https://forum.inductiveautomation.com/t/gateway-event-script-not-triggering-on-tag-change/57005/14 "2022-03-24T11:36:12Z")

</div>

`system.tag.write` is asynchronous. Replace that with writeBlocking or writeSynchronous and capture the quality code returned.
