# Dynamic Delay Timer in Gateway Event Scripts

**URL:** <https://forum.inductiveautomation.com/t/dynamic-delay-timer-in-gateway-event-scripts/39251>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [October 1, 2020, 6:17am UTC](https://forum.inductiveautomation.com/t/dynamic-delay-timer-in-gateway-event-scripts/39251 "2020-10-01T06:17:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![manju.p](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@manju.p](https://forum.inductiveautomation.com/u/manju.p)\
**Post date:** [October 1, 2020, 6:17am UTC](https://forum.inductiveautomation.com/t/dynamic-delay-timer-in-gateway-event-scripts/39251/1 "2020-10-01T06:17:27Z")

</div>

I’m new to the ignition perspective. In Gateway event scripts under Timer is there any possible way to make Time Delay (ms) to be Dynamic or fetch Time Delay (ms) from Database.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/9/f97708db6d0b965c9eb625ae3a41dad23dbe3244.png)

---

<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 1, 2020, 12:14pm UTC](https://forum.inductiveautomation.com/t/dynamic-delay-timer-in-gateway-event-scripts/39251/2 "2020-10-01T12:14:22Z")

</div>

Run a timer at a much shorter interval (per your precision requirements) and check in your own logic whether nested logic is "due". I recommend using a datetime memory tag to hold the "next due" timestamp. See this similar topic:

> [@Gateway tag change or Gateway timer scripts expressions and delays](http://forum.inductiveautomation.com/t/gateway-tag-change-or-gateway-timer-scripts-expressions-and-delays/39147/5):
>
> Something like this (I would delegate to a script module): tagpaths = ['[default]'+y for y in ['Cond1', 'Cond2', 'NotBefore']] def conditionalRun(event): cond1, cond2, notbefore = [x.value for x in system.tag.readAll(tagpaths)] # Check run permissives if cond1 and cond2: # Check Not Before criteria now = system.date.now() if now.before(notbefore): return system.tag.write(tagpaths[-1], system.date.addDays(now, 14)) # Do actions that must not repeat faster that every two weeks.…

---

<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:** [October 1, 2020, 5:14pm UTC](https://forum.inductiveautomation.com/t/dynamic-delay-timer-in-gateway-event-scripts/39251/3 "2020-10-01T17:14:45Z")

</div>

There are several ways to approach this. Definitely use @pturmel recommendation to run.every second (+/- as needed) and check on other conditions to decide if it is time to run or not.

Personally, I find it easy to watch and control executions with integer memory tags. Something like:

```auto
tagPaths = []
tagPaths.append( 'secondsToNextRun' )
tagPaths.append( 'secondsBetweenRuns' )
tagValues = system.tag.readBlocking( tagPaths )
secondsToNextRun = tagValues[0].value
secondsBetweenRuns = tagValues[1].value

if secondsToNextRun < 1:
	# run your process here then reset the secondsToNextRun
	system.tag.writeBlocking( ['secondsToNextRun'], [secondsBetweenRuns] )
 )
else:
	system.tag.writeBlocking( ['secondsToNextRun'], [secondsToNextRun - 1] )

```

This will give you the ability to dynamically change the value of secondsBetweenRuns via machine or business logic or Perspective Views available to the personnel responsible for them.  
I usually also include a Boolean tag to indicate if the process should run or not and you can trigger that with safety rules, machine rules, business logic or Perspective Views.
