# Tag change gateway events initialChange and executionCount

**URL:** <https://forum.inductiveautomation.com/t/tag-change-gateway-events-initialchange-and-executioncount/113123>\
**Category:** Ignition\
**Tags:** perspective, ignition81, scripting\
**Created:** [January 7, 2026, 12:40pm UTC](https://forum.inductiveautomation.com/t/tag-change-gateway-events-initialchange-and-executioncount/113123 "2026-01-07T12:40:26Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![svatsal77](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@svatsal77](https://forum.inductiveautomation.com/u/svatsal77)\
**Post date:** [January 7, 2026, 12:40pm UTC](https://forum.inductiveautomation.com/t/tag-change-gateway-events-initialchange-and-executioncount/113123/1 "2026-01-07T12:40:26Z")

</div>

I have two tags configured under gateway Tag change event,  
Both the tag values are changed at same time.  
Sometimes after reseting the gateway or saving the project, even if there is a change in both the tags the script is executed only once, after that if there is no change in project or gateway is not resetted the script is firred twice.  
Correct me or please give your thoughts on this

When a project is saved, or the gateway is restarted/reset, the **Tag Change Script** behaves differently because of two key variables:

- `initialChange`

- `executionCount`

### **What happens after a project save or gateway restart?**

1. For the first tag in the hierarchy ( **Tag1** ):

2. For the second tag ( **Tag2** ):

### 

This means:

- When `executionCount` is **1** (as with Tag1 right after restart), the main logic is skipped.

- For Tag2, `executionCount` is **2** , so the logic runs normally.

* * *

✅ **In short:**  
After a restart/save, the first tag in the hierarchy is treated as an initial change with `executionCount = 1`, so I think condition prevents its logic from running. Subsequent tags and all future runs behave normally because `executionCount` increments beyond 1.

here is the script

````python
if initialChange:
	pass
elif executionCount <= 1:
    pass
else:
	
 some logic here
			```
````

---

<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:** [January 7, 2026, 1:17pm UTC](https://forum.inductiveautomation.com/t/tag-change-gateway-events-initialchange-and-executioncount/113123/2 "2026-01-07T13:17:09Z")

</div>

I am currious what you are actually trying to achieve with the execution count. I have never needed to worry about this.

Any time Gateway scripts are restarted, the execution count will be reset to 0.

See:

> **[Tag Change Objects​ - Gateway Event Scripts | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/platform/scripting/scripting-in-ignition/gateway-event-scripts#tag-change-objects)**
>
> Gateway Event Scripts are scripts that run directly on the Gateway. They are useful because they always run, regardless if any sessions or clients are open. They also provide a guaranteed way to make sure only a single execution of a particular...

Specifically:

> Whenever you make changes to your project that affect scripts—like updating your project library or modifying event scripts—all the event scripts, including timers, scheduled scripts, and tag change scripts, are restarted. Once restarted, your executionCount will be reset to 0.

This means the first trip through the scirpt `initialChange` will be `True` and `executionCount` will be 1, the second trip through `initialChange` will be `False`, and `executionCount` will be 2.

Any project save where **any** Gateway Events are changed, this script will be skipped on the first execution.

I am pretty confident this is how it works if the event is only triggered by a single tag, I am not as certain how additional trigger tags interact. ~~What I expect is that since events are queued, and these would be triggered by subscription at essentially the same time, that value of these flags would be the same across both tag events. That may not be the case though, and I haven't done any testing to confirm.~~ (See Kevin's response below).

For what it's worth (not much) I would write the logic like this:

```python
if not initialChange and executionCount > 1:
    #some logic here

```

I find it more readable, really either is fine and both work the same.

---

<div class="post-metadata">

**Author:** ![svatsal77](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@svatsal77](https://forum.inductiveautomation.com/u/svatsal77)\
**Post date:** [January 7, 2026, 1:20pm UTC](https://forum.inductiveautomation.com/t/tag-change-gateway-events-initialchange-and-executioncount/113123/3 "2026-01-07T13:20:58Z")

</div>

executionCount is incremented at the end of script or at the starting of the script?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [January 7, 2026, 1:30pm UTC](https://forum.inductiveautomation.com/t/tag-change-gateway-events-initialchange-and-executioncount/113123/4 "2026-01-07T13:30:26Z")

</div>

You'll want to check your change triggers too. Options are value, quality, and timestamp. I usually only use `value`

---

<div class="post-metadata">

**Author:** ![svatsal77](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@svatsal77](https://forum.inductiveautomation.com/u/svatsal77)\
**Post date:** [January 7, 2026, 1:43pm UTC](https://forum.inductiveautomation.com/t/tag-change-gateway-events-initialchange-and-executioncount/113123/5 "2026-01-07T13:43:39Z")

</div>

I have only configured it to 'value'

---

<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:** [January 7, 2026, 1:51pm UTC](https://forum.inductiveautomation.com/t/tag-change-gateway-events-initialchange-and-executioncount/113123/6 "2026-01-07T13:51:26Z")

</div>

I think the docs are wrong/misleading.

It's intentional that `initialChange` is `true` when `executionCount == 1`.

`executionCount` increments before the script is executed, you can think of it as "this is the Nth execution".

In fact, `initialChange` is assigned as:

```java
long executionCount = execStats.executionCount.incrementAndGet();
boolean initialChange = executionCount == 1

```

---

<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:** [January 7, 2026, 2:16pm UTC](https://forum.inductiveautomation.com/t/tag-change-gateway-events-initialchange-and-executioncount/113123/7 "2026-01-07T14:16:34Z")

</div>

So `if initialChange` and `if executionCount <= 1` are logically equivalent.

How do these values intereact with multiple trigger tags set?

---

<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:** [January 7, 2026, 2:20pm UTC](https://forum.inductiveautomation.com/t/tag-change-gateway-events-initialchange-and-executioncount/113123/8 "2026-01-07T14:20:02Z")

</div>

~~The list being able to contain many tags is just a convenience. They aren't any kind of atomic unit. The script is the thing being executed and counted, regardless of what tag triggers it.~~

~~One tag will end up being the first execution / initial change. That's all there is to it.~~

---

<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:** [January 7, 2026, 2:30pm UTC](https://forum.inductiveautomation.com/t/tag-change-gateway-events-initialchange-and-executioncount/113123/9 "2026-01-07T14:30:16Z")

</div>

> [@Kevin.Herron](#):
>
> The script is the thing being executed and counted, regardless of what tag triggers it.

Definately not how I thought it worked.

Also, seems like it would result in potential false triggers with many triggers configured.

Would you say, that if your script must only be triggered on true changes, then best practice would be to have an event per 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:** [January 7, 2026, 2:33pm UTC](https://forum.inductiveautomation.com/t/tag-change-gateway-events-initialchange-and-executioncount/113123/10 "2026-01-07T14:33:17Z")

</div>

For gateway tag change event scripts that may be what's necessary.

edit: let me double check all this and make sure the execution count isn't per tag path. I might be wrong.

---

<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:** [January 7, 2026, 2:38pm UTC](https://forum.inductiveautomation.com/t/tag-change-gateway-events-initialchange-and-executioncount/113123/11 "2026-01-07T14:38:47Z")

</div>

Ok I was wrong:

```python
| I [Project] [14:37:19.469]: Restarting gateway scripts... project=Test81, collection=Test81
| tagPath=[default]Tag1 initialChange=1 executionCount=1
| tagPath=[default]Tag2 initialChange=1 executionCount=1

```

So what I said about executionCount being 1 when initialChange is true remains, but it's per tag path, not per script.

Now I'm not even sure what this thread was about.
