# Gateway tag change script not executing

**URL:** <https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-executing/115637>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [May 21, 2026, 11:58am UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-executing/115637 "2026-05-21T11:58:08Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![cdelacruz](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@cdelacruz](https://forum.inductiveautomation.com/u/cdelacruz)\
**Post date:** [May 21, 2026, 11:58am UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-executing/115637/1 "2026-05-21T11:58:08Z")

</div>

Good Morning, I’m writing a script for my OEE monitoring system to monitor the number of active and down machines for all the machines in the shop. I’m using a tag change script that executes when the boolean value of selected tags changes. The original script is below:

########################################################################

```python
# Specify the paths.
paths = [
    "[default]Machines/Machine_Information_Template/Machine_Activity/Down",
    "[default]Machines/MT_Robot/Machine_Activity/Down"
    
    #^add your tag path for a new machine above
]

active = 0
down = 0

# Read tags
values = system.tag.readBlocking(paths)

# Loop through results
for i in range(len(values)):
    tagValue = values[i].value

    if tagValue == False:
        active += 1
    else:
        down += 1

print active
print down
system.tag.writeBlocking("[default]Main_Metrics/Overall/Active_Machines", active)
system.tag.writeBlocking("[default]Main_Metrics/Overall/Down_Machines", down)

```

########################################################################

In the first iteration, everything was working fine. I updated the code so that the paths in my machine folder associated with the "down" tag is generated automatically, eliminating the need to hardcode the tag paths for each machine.

The code still runs as expected in the Script Console, but not when triggered by the tag change event.

Here is the updated version of the code:

########################################################################

```python
# Find all tags named "Down" under machine folder
def findTagsNamedDown(path):
    found = []
    results = system.tag.browse(path)

    for r in results.getResults():
        name = r["name"]
        fullPath = r["fullPath"]
        hasChildren = r["hasChildren"]

        if name == "Down":
            #Store string path
            found.append(str(fullPath))

        if hasChildren:
            found.extend(findTagsNamedDown(fullPath))

    return found

baseFolder = "[default]Machines"

#Find all Down tags
paths = findTagsNamedDown(baseFolder)

#Make sure every entry is a string
paths = [str(p) for p in paths]

#Count active vs down
active = 0
down = 0

values = system.tag.readBlocking(paths)

for v in values:
    tagValue = v.value

    if tagValue == False:
        active += 1
    else:
        down += 1

print active
print down

# Write machine status values to active and down machines tags
system.tag.writeBlocking("[default]Main_Metrics/Overall/Active_Machines", active)
system.tag.writeBlocking("[default]Main_Metrics/Overall/Down_Machines", down)

```

########################################################################

Any guidance would be greatly appreciated. I've also attached screenshots of the gateway event script configuration and script console. Thank you!

 ![{366E8F9F-1A7B-43F8-9E62-070714A2F5B2}](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/e/1e960e52cd355f29019c91bc25ebcd679eb20ffd.png)

 ![{F112BC92-3210-403D-A04C-DE0C1566DAAD}](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/f/4fe12e2a7ddd15b3c7e2c090aad1a47804d3b42c.png)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 21, 2026, 12:18pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-executing/115637/2 "2026-05-21T12:18:43Z")

</div>

I am away from my computer, but I think you’ve made this harder than it needs to be. Tag Change events have all the information you need without browsing or reading the values.

When I get back to my desk, I’ll type something up

---

<div class="post-metadata">

**Author:** ![mpoulsen921](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mpoulsen921](https://forum.inductiveautomation.com/u/mpoulsen921)\
**Post date:** [May 21, 2026, 12:29pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-executing/115637/3 "2026-05-21T12:29:30Z")

</div>

Yea, agreed with lrose.

Your script should look somehting like this:

```python
activeMachines, downMachines = [qv.value for qv in system.tag.readBlocking(["default]Main_Metrics/Overall/Active_Machines","[default]Main_Metrics/Overall/Down_Machines"])]

if newValue.value == False and previousValue.value == True:
    activeMachines += 1
    downMachines -= 1

elif newValue.value == True and previousValue.value == False:
    activeMachines -= 1
    downMachines += 1

system.tag.writeBlocking(["[default]Main_Metrics/Overall/Active_Machines","[default]Main_Metrics/Overall/Down_Machines"], [activeMachines,downMachines]))

```

The tag event script will be triggered every time one of the tags included in the Tag Path(s) list is changing. So you would need to read the number of active and down machines first and then adjust the numbers based on the the specific down tag that is changing.

EDIT: Updated the script based on lrose comment.

---

<div class="post-metadata">

**Author:** ![cdelacruz](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@cdelacruz](https://forum.inductiveautomation.com/u/cdelacruz)\
**Post date:** [May 21, 2026, 12:45pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-executing/115637/4 "2026-05-21T12:45:36Z")

</div>

This worked, thank you! I got a bit ahead of myself and didn't realize that the tag change event did that for you.

---

<div class="post-metadata">

**Author:** ![tgarrison](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tgarrison/32/80965_2.png) [@tgarrison](https://forum.inductiveautomation.com/u/tgarrison)\
**Post date:** [May 21, 2026, 12:56pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-executing/115637/5 "2026-05-21T12:56:32Z")

</div>

also for future reference, use the system.tag.query instead of system.tag.browse. You'll find it much faster, and you can do some nice pre-filtering with it, and also specify return values.

---

<div class="post-metadata">

**Author:** ![mpoulsen921](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mpoulsen921](https://forum.inductiveautomation.com/u/mpoulsen921)\
**Post date:** [May 21, 2026, 12:58pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-executing/115637/6 "2026-05-21T12:58:19Z")

</div>

... And use the Tag Report Tool to generate the filtering and copy the system.tag.query()-function from there.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 21, 2026, 1:28pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-executing/115637/7 "2026-05-21T13:28:28Z")

</div>

Except don't use multiple reads and writes.

```python
activeMachines, downMachines = [qv.value for qv in system.tag.readBlocking(["default]Main_Metrics/Overall/Active_Machines","[default]Main_Metrics/Overall/Down_Machines"])]

if newValue.value == False and previousValue.value == True:
    activeMachines += 1
    downMachines -= 1

elif newValue.value == True and previousValue.value == False:
    activeMachines -= 1
    downMachines += 1

system.tag.writeBlocking(["[default]Main_Metrics/Overall/Active_Machines","[default]Main_Metrics/Overall/Down_Machines"], [activeMachines,downMachines]))
```

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 21, 2026, 2:27pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-executing/115637/8 "2026-05-21T14:27:40Z")

</div>

> [@tgarrison](#):
>
> use the system.tag.query instead of system.tag.browse

> [@tgarrison](#):
>
> You'll find it much faster,

In my testing I actually found that browse was faster to execute, I don't recall by how much. I don't remember it being too significant though, just thought I'd mention.

---

<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:** [May 21, 2026, 2:33pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-executing/115637/9 "2026-05-21T14:33:30Z")

</div>

> [@nminchin](#):
>
> browse was faster to execute

Unless you need more that just the tag path, or to filter on more than just the few options supported by `.browse()`, or filter by complex combinations. `system.tag.query()` can return the current value and any desired current property values, in the one call. Avoiding the need for a followup `system.tag.readBlocking()`.

However, `system.tag.query()` is always recursive.

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [May 21, 2026, 6:21pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-executing/115637/10 "2026-05-21T18:21:28Z")

</div>

My problem with this is there's a possibility it gets out of sync and then operations or upper management will blame the program for not showing correct values and questioning if they could trust it all along.

Not sure if you ever do updates to servers during operations, but if so, it will most likely get out of sync during that too.

I think you were on a better track to start with by grabbing the current status of all "down" tags using the `system.tag.query` function and just using that instead of incrementing/decrementing values.

Or if you wanted to keep things from ever drifting or getting out of sync, you could have a scheduled time every day where it grabs the current status and updates the values of active/down machines so that the normal tag change script can adjust it from there.

---

<div class="post-metadata">

**Author:** ![mpoulsen921](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@mpoulsen921](https://forum.inductiveautomation.com/u/mpoulsen921)\
**Post date:** [May 21, 2026, 7:37pm UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-not-executing/115637/11 "2026-05-21T19:37:41Z")

</div>

Yeah, I fully agree there is a big risk of this getting out of sync and another approach could be to run this on a schedule or a mix of the two.

I did not really take into consideration whether the approach of OP was the best or not. I just wanted to help out with the question at hand as to why the script was only working in the script console.
