# Gateway Tag Change Script stuck after few hours

**URL:** <https://forum.inductiveautomation.com/t/gateway-tag-change-script-stuck-after-few-hours/63303>\
**Category:** Ignition\
**Tags:** ignition80, scripting\
**Created:** [August 23, 2022, 2:59am UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-stuck-after-few-hours/63303 "2022-08-23T02:59:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kairongsen](https://avatars.discourse-cdn.com/v4/letter/k/eb9ed0/32.png) [@kairongsen](https://forum.inductiveautomation.com/u/kairongsen)\
**Post date:** [August 23, 2022, 2:59am UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-stuck-after-few-hours/63303/1 "2022-08-23T02:59:18Z")

</div>

Hi all,

Currently I am facing a problem with Gateway Tag Change Script.  
Here is the details:  
The tags are from KEPServer EX v6.9.572.0  
We have another system that will write to the tags in KEPServer let it be System A  
The ignition we are using is v8.0.17  
Both Ignition and System have R/W permission

Here is the process flow  
When System A write value 1 to tag, Ignition will executed the script and update the tag value back to 0. Everything run smoothly for few hours but later on when the Tag is being update to 1. It will stuck there for whole day. (Remain as value 1)

System A\>Kepware\>Ignition  
Ignition\>Kepware\>System A

Change triggers=Value and Timestamp  
How update the tag using system.tag.read() and system.tag.write()

---

<div class="post-metadata">

**Author:** ![nideyijuyidong](https://avatars.discourse-cdn.com/v4/letter/n/7cd45c/32.png) [@nideyijuyidong](https://forum.inductiveautomation.com/u/nideyijuyidong)\
**Post date:** [August 23, 2022, 3:09am UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-stuck-after-few-hours/63303/2 "2022-08-23T03:09:42Z")

</div>

I use a timestamp tag. And check the timestamp in tagValue change script.

```auto
	if not initialChange:
		source_timestamp_tag=system.tag.readBlocking(["[.]State/FJ_source_timestamp",])
		now=system.date.now()
		second_between=system.date.secondsBetween(source_timestamp_tag[0].value, now)
		if second_between>8:
			result=1 if currentValue.value else 0
			system.tag.writeBlocking(["[.]Source/FJ_On",],[result,])

```

---

<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:** [August 23, 2022, 3:17am UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-stuck-after-few-hours/63303/3 "2022-08-23T03:17:02Z")

</div>

> [@kairongsen](#):
>
> When System A write value 1 to tag, Ignition will executed the script and update the tag value back to 0.

This is an anti-pattern that is prone to race conditions outside of Ignition's control. Instead, use two separate tags, where the responding system "echoes" the trigger value into the second tag. Each tag is only written by one system. It is the only certain way to avoid races when writes from two directions conflict.

(I prefer to use 8-bit integers instead of booleans for this, triggering by incrementing.)

---

<div class="post-metadata">

**Author:** ![kairongsen](https://avatars.discourse-cdn.com/v4/letter/k/eb9ed0/32.png) [@kairongsen](https://forum.inductiveautomation.com/u/kairongsen)\
**Post date:** [August 23, 2022, 3:22am UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-stuck-after-few-hours/63303/4 "2022-08-23T03:22:05Z")

</div>

Are you suggesting to add a timestamp tag as a checker? If the timestamp of the event trigger tag remain idle for a certain amount of time then launch the script?

---

<div class="post-metadata">

**Author:** ![nideyijuyidong](https://avatars.discourse-cdn.com/v4/letter/n/7cd45c/32.png) [@nideyijuyidong](https://forum.inductiveautomation.com/u/nideyijuyidong)\
**Post date:** [August 23, 2022, 3:52am UTC](https://forum.inductiveautomation.com/t/gateway-tag-change-script-stuck-after-few-hours/63303/5 "2022-08-23T03:52:06Z")

</div>

I realize our situations are not exactly the same, but yes, use a timestamp to terminate the loop call.  
But it’s actually better to move the scripts from both systems into the PLC, if possible.
