# Write values to a tag on a Tag Change Script

**URL:** <https://forum.inductiveautomation.com/t/write-values-to-a-tag-on-a-tag-change-script/20088>\
**Category:** Ignition\
**Created:** [October 11, 2018, 2:44pm UTC](https://forum.inductiveautomation.com/t/write-values-to-a-tag-on-a-tag-change-script/20088 "2018-10-11T14:44:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pascal](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pascal](https://forum.inductiveautomation.com/u/pascal)\
**Post date:** [October 11, 2018, 2:44pm UTC](https://forum.inductiveautomation.com/t/write-values-to-a-tag-on-a-tag-change-script/20088/1 "2018-10-11T14:44:32Z")

</div>

Hello, i’m looking for the best way to write to an OPC boolean when a tag changes. Once ‘true’ is written on the boolean tag, I’d like to wait 1 second and write a ‘false’ value back.  
I need this script to run all the time so I tried using a Tag change script (in Gateway Event Script). I know from other posts on this forum that in order to put a delay on a script, time.sleep() must not be used risking the gui to freeze.  
However the system.util.invokeLater doesn’t work on the gateway scope, so what is the method to follow in order to do what I want?

---

<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:** [October 11, 2018, 3:01pm UTC](https://forum.inductiveautomation.com/t/write-values-to-a-tag-on-a-tag-change-script/20088/2 "2018-10-11T15:01:03Z")

</div>

There is no official way to run something “later” in the gateway. The closest would be to use a sleep inside of a invokeAsynchronous() thread. If you do this often, consider using a fast timer event script, checking a timestamp to tell it when to write false.

Another possibility would be to use the ‘invokeLater’ emulation from [later.py](https://www.automation-pros.com/ignition/later.py). It uses an unofficial interface, though.

---

<div class="post-metadata">

**Author:** ![Phil\_B](https://avatars.discourse-cdn.com/v4/letter/p/c89c15/32.png) [@Phil\_B](https://forum.inductiveautomation.com/u/Phil_B)\
**Post date:** [October 11, 2018, 5:51pm UTC](https://forum.inductiveautomation.com/t/write-values-to-a-tag-on-a-tag-change-script/20088/3 "2018-10-11T17:51:46Z")

</div>

I ran into a similar issue a short time ago. what we did was make an expression tag with dateExtract(now(1000),“second”) as the expression and a tag change script that checked if the other tag = true then write false to the other tag. the only thing with this method is that if the tag changes to true in the middle of a second, you wont get a full second before it turns false again.

---

<div class="post-metadata">

**Author:** ![pascal](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pascal](https://forum.inductiveautomation.com/u/pascal)\
**Post date:** [October 12, 2018, 6:49am UTC](https://forum.inductiveautomation.com/t/write-values-to-a-tag-on-a-tag-change-script/20088/4 "2018-10-12T06:49:55Z")

</div>

Thanks alot pturmel.  
I have put the later.py code in a shared script and used the writeTagLater and it works perfect.  
Thanks again ! 👍
