# Imitate leased scanclass in gateway script

**URL:** <https://forum.inductiveautomation.com/t/imitate-leased-scanclass-in-gateway-script/17658>\
**Category:** Ignition\
**Created:** [April 10, 2018, 12:57pm UTC](https://forum.inductiveautomation.com/t/imitate-leased-scanclass-in-gateway-script/17658 "2018-04-10T12:57:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcarritt1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mcarritt1/32/4262_2.png) [@mcarritt1](https://forum.inductiveautomation.com/u/mcarritt1)\
**Post date:** [April 10, 2018, 12:57pm UTC](https://forum.inductiveautomation.com/t/imitate-leased-scanclass-in-gateway-script/17658/1 "2018-04-10T12:57:44Z")

</div>

I have a few different ideas on how to handle this, but not sure what the BEST way to go about it would be.

I have a script that I really want to run only 60 seconds, but it doesn’t need to run if nobody is looking at screen X.

I could of course put an if statement in the gateway timer script that checks for a flag that the window is open somewhere, but I want the script to run right away when the screen is first opened. I don’t want the user to wait for the 60s timer to run again before getting fresh data. Additionally, if another client opens the screen it shouldn’t cause a new run, just continue running every 60s.

I’m sure I’m missing something obvious here, thanks!

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [April 10, 2018, 1:30pm UTC](https://forum.inductiveautomation.com/t/imitate-leased-scanclass-in-gateway-script/17658/2 "2018-04-10T13:30:28Z")

</div>

I often use a specially created trigger tag for this purpose.

Just create a memory tag (a boolean is enough), and use a “Value Changed” script on that tag (or a gateway tag changed event).

When you have this, you can toggle the tag from anywhere, and execute the script.

- You can trigger it when the window is opened
- You can add a gateway timer to toggle it every minute if you want it to be independent from the open clients
- You can add a gui timer that toggles the tag every minute, perhaps check the timestamp to ensure two clients don’t cause double the toggle speed
- You can offer a “refresh” button in the GUI to force executing the script

---

<div class="post-metadata">

**Author:** ![mcarritt1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mcarritt1/32/4262_2.png) [@mcarritt1](https://forum.inductiveautomation.com/u/mcarritt1)\
**Post date:** [April 10, 2018, 1:31pm UTC](https://forum.inductiveautomation.com/t/imitate-leased-scanclass-in-gateway-script/17658/3 "2018-04-10T13:31:53Z")

</div>

ah the gateway timer to toggle the trigger every minute was what i was missing. duh! thanks!

---

<div class="post-metadata">

**Author:** ![martinel37461](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@martinel37461](https://forum.inductiveautomation.com/u/martinel37461)\
**Post date:** [April 11, 2018, 12:57pm UTC](https://forum.inductiveautomation.com/t/imitate-leased-scanclass-in-gateway-script/17658/4 "2018-04-11T12:57:44Z")

</div>

You could also use a Boolean expression tag (e.g. customTimer) with an expression like:

> getMinute(now()) % 2 = 0

With a driven scan class that runs whenever the value of customTimer changes, you can change the timing by editing the expression.
