# Reinitialize Memory Tag in UDT everyday

**URL:** <https://forum.inductiveautomation.com/t/reinitialize-memory-tag-in-udt-everyday/32886>\
**Category:** Ignition\
**Created:** [March 6, 2020, 3:42pm UTC](https://forum.inductiveautomation.com/t/reinitialize-memory-tag-in-udt-everyday/32886 "2020-03-06T15:42:41Z")\
**Posts on this page:** 3\
**Page:** 1

<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:** [March 6, 2020, 3:42pm UTC](https://forum.inductiveautomation.com/t/reinitialize-memory-tag-in-udt-everyday/32886/1 "2020-03-06T15:42:41Z")

</div>

What would be the best method for setting a memory tag inside a UDT to 0 at a certain time, like midnight every day. My first thought is to loop through the udt instances and write 0 to each tag in a gateway script. Is there a better way to handle this?

---

<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:** [March 6, 2020, 4:06pm UTC](https://forum.inductiveautomation.com/t/reinitialize-memory-tag-in-udt-everyday/32886/2 "2020-03-06T16:06:24Z")

</div>

How precise do you need to be? If you have some leeway, a gateway timer event that runs frequently can check a memory tag with the last reset timestamp, compute a “next due” timestamp, and compare against now(). This is practical for accuracy in the seconds to minutes range.

For accuracy within the first second or two of a given minute, consider using unsupported access to Ignition’s gateway scheduler via `IgnitionGateway` (`SRContext` in v7.9 and before). You want the fixed-rate delayed scheduler [.scheduledExecutorService.scheduleAtFixedRate()](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledExecutorService.html#scheduleAtFixedRate-java.lang.Runnable-long-long-java.util.concurrent.TimeUnit-). Use an initial delay to set the right time-of-day, and a 24-hour period.

Edit: That method returns a Future that can be used to cancel the scheduled event. You should tuck that into the system.util.getGlobals() dictionary. Use that to cancel a prior schedule if your script module is restarted.

---

<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:** [March 6, 2020, 4:11pm UTC](https://forum.inductiveautomation.com/t/reinitialize-memory-tag-in-udt-everyday/32886/3 "2020-03-06T16:11:30Z")

</div>

Good deal. I think I remember testing some scripting you posted on doing time specific tasks with a gateway timer script to ensure running once and only once at a certain time. I can’t wait for crontab scheduling. In the meantime, that should work. I just wanted to make sure I wasn’t missing any UDT magic shortcut.
