# Gateway event script sometimes fails to execute a function

**URL:** <https://forum.inductiveautomation.com/t/gateway-event-script-sometimes-fails-to-execute-a-function/36539>\
**Category:** Ignition\
**Created:** [July 9, 2020, 1:36pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sometimes-fails-to-execute-a-function/36539 "2020-07-09T13:36:04Z")\
**Posts on this page:** 10\
**Page:** 2

<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:** [July 10, 2020, 3:35pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sometimes-fails-to-execute-a-function/36539/21 "2020-07-10T15:35:27Z")

</div>

It is not clear in this post if you are really using a Tag Change Script in a project’s Gateway Event scripts, or if you are using a ValueChange or other event directly on a tag. The former are in a project and have access to that project’s script modules (and any inherited scripts in v8). The latter are not in a project and have access only to shared scripts (v7.9) or to the script modules in the Global Scripting Project (v8).

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [July 10, 2020, 3:48pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sometimes-fails-to-execute-a-function/36539/22 "2020-07-10T15:48:08Z")

</div>

About to start testing them again and watching closely to the data this time.

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [July 10, 2020, 4:05pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sometimes-fails-to-execute-a-function/36539/23 "2020-07-10T16:05:32Z")

</div>

I’m super confused at this point. The only thing that might make sense is the PCs are running different versions of Java…

---

<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 10, 2020, 4:13pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sometimes-fails-to-execute-a-function/36539/24 "2020-07-10T16:13:16Z")

</div>

Try copying the script into the script console, make it a function and then call it at the bottom of the console.  
This is an easy way to see any errors that pop up in both the main script and the sub function call.  
Something like:

```auto
testTagCall(initialChange):
    if not initialChange:
        var_Furnace = '1W'
        tempReached = system.tag.read('somePath').value
        tempReachedAck = system.tag.read('somePath').value

        if tempReachedAck == 1:
            pass
        else:
            pairID = system.tag.read('somePath).value
            id1 = system.tag.read('somePath').value
            id2 = system.tag.read('somePath').value

            if pairID > 0:
                #THIS LINE SOMETIMES RUNS
                project.functions.tempReached(var_Furnace, id1, id2) 

                #THIS LINE ALWAYS RUNS
                system.tag.write('somePath', 1)
                return var_Furnace,id1,id2
print testTagCall(0)

```

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [July 10, 2020, 4:20pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sometimes-fails-to-execute-a-function/36539/25 "2020-07-10T16:20:22Z")

</div>

> [@MMaynard](#):
>
> project.functions.tempReached(var\_Furnace, id1, id2)

No errors popped up. Would this function execute? My Gateway logger doesn't show that function executing (I use an info logger inside the function).

---

<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 10, 2020, 4:24pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sometimes-fails-to-execute-a-function/36539/26 "2020-07-10T16:24:25Z")

</div>

Return/Print other variables in the call

```auto
return PairID,id1,id2

```

Or you can just print them right inline

```auto
if tempReachedAched == 1:
    pairID = system.tag.read(;somePath').value
    print pairID

```

etc.

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [July 10, 2020, 5:23pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sometimes-fails-to-execute-a-function/36539/27 "2020-07-10T17:23:50Z")

</div>

![example_script3](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/5/85093fc025c1ddd55b11346daf560d216adda80c.jpeg)

So the attached picture executes and returns what I expect from the function and also updates the tags in the program. However, the function itself doesn’t write anything to the gateway logger.

```
def soakPointReached1(furnaceName, uid1, uid2):
    dewaxLogger = system.util.getLogger("Dewax")
    dewaxLogger.info('Executing func soakPointReached1')
    return 3

```

Thoughts?

Sidenote: I figured out why my second picture in this thread wasn’t executing. The function being called was looking at a local directory to delete some CSV file. Obviously this directory doesn’t exist on the gateway (at least I hope it doesnt)

Sidenote2: My original problem I’ve been unable to replicate. We ran 8 furnaces back to back and all performed as expected. So it’s looking more and more like user error on my part.

---

<div class="post-metadata">

**Author:** ![BillS](https://avatars.discourse-cdn.com/v4/letter/b/9fc348/32.png) [@BillS](https://forum.inductiveautomation.com/u/BillS)\
**Post date:** [July 15, 2020, 11:26pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sometimes-fails-to-execute-a-function/36539/28 "2020-07-15T23:26:19Z")

</div>

I’m curious to know if you have the dedicated thread option turned on for this tag change event script?

I’m sure that certain people whom have already posted on this thread have some good insites to offer on the the impact of doing relatively long processes inside tag change scripts (Database Updates/File System Modifications) could have on your system if you are using shared threading.

Bill

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [July 16, 2020, 1:29am UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sometimes-fails-to-execute-a-function/36539/29 "2020-07-16T01:29:29Z")

</div>

This is version 7.9 and I don’t see a threading option for gateway tag change scripts.

I haven’t seen this issue since the first time it happened so either it’s a very rare event or it’s not a real problem… will investigate 1 more week and then probably close this thread.

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [July 16, 2020, 12:15pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sometimes-fails-to-execute-a-function/36539/30 "2020-07-16T12:15:55Z")

</div>

> I’m curious to know if you have the dedicated thread option turned on for this tag change event script?

This option is for Timer scripts.

[Previous page](https://forum.inductiveautomation.com/t/gateway-event-script-sometimes-fails-to-execute-a-function/36539.md?page=1)
