# Gateway Event Scripts - Timer Script / Scheduled Script

**URL:** <https://forum.inductiveautomation.com/t/gateway-event-scripts-timer-script-scheduled-script/83165>\
**Category:** Ignition\
**Created:** [December 14, 2023, 8:40pm UTC](https://forum.inductiveautomation.com/t/gateway-event-scripts-timer-script-scheduled-script/83165 "2023-12-14T20:40:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![HelloWorld](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@HelloWorld](https://forum.inductiveautomation.com/u/HelloWorld)\
**Post date:** [December 14, 2023, 8:40pm UTC](https://forum.inductiveautomation.com/t/gateway-event-scripts-timer-script-scheduled-script/83165/1 "2023-12-14T20:40:35Z")

</div>

Can a Gateway Schedule and its script be created in a Gateway Timer Script and/or vis versa. A timer script created in a Gateway Scheduled Script.

---

<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:** [December 14, 2023, 8:46pm UTC](https://forum.inductiveautomation.com/t/gateway-event-scripts-timer-script-scheduled-script/83165/2 "2023-12-14T20:46:32Z")

</div>

There's no way to programmatically create these event scripts, if that is what you mean. Otherwise, please elaborate on what you are trying to do (and why).

---

<div class="post-metadata">

**Author:** ![HelloWorld](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@HelloWorld](https://forum.inductiveautomation.com/u/HelloWorld)\
**Post date:** [December 14, 2023, 8:58pm UTC](https://forum.inductiveautomation.com/t/gateway-event-scripts-timer-script-scheduled-script/83165/3 "2023-12-14T20:58:42Z")

</div>

In my question I mean programmatically. What I am trying to do is - aiming to automate the creation of new entries in the `SampleEvent` table based on the `SampleSchedule` intervals. In a timer script I am running a named query to get samples that need to be taken from a schedule table. I go through the samples that need to be taken and based on the offset and interval in the schedule table, take these samples at a set interval until a status says not too. I know it could be done in one master script, but if I could create these schedules dynamically it would be more organized.

---

<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:** [December 14, 2023, 9:00pm UTC](https://forum.inductiveautomation.com/t/gateway-event-scripts-timer-script-scheduled-script/83165/4 "2023-12-14T21:00:45Z")

</div>

Sorry, not possible. I would run a scheduled event at one or five minute intervals (or slower--depends how precise you need to be) and queue up whatever operations have come due.

---

<div class="post-metadata">

**Author:** ![HelloWorld](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@HelloWorld](https://forum.inductiveautomation.com/u/HelloWorld)\
**Post date:** [December 14, 2023, 9:01pm UTC](https://forum.inductiveautomation.com/t/gateway-event-scripts-timer-script-scheduled-script/83165/5 "2023-12-14T21:01:47Z")

</div>

Thanks.

---

<div class="post-metadata">

**Author:** ![HelloWorld](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@HelloWorld](https://forum.inductiveautomation.com/u/HelloWorld)\
**Post date:** [December 18, 2023, 1:29pm UTC](https://forum.inductiveautomation.com/t/gateway-event-scripts-timer-script-scheduled-script/83165/6 "2023-12-18T13:29:39Z")

</div>

Can I define and use functions inside def onScheduledEvent() ? Or should they be defined in Scripting?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [December 18, 2023, 1:37pm UTC](https://forum.inductiveautomation.com/t/gateway-event-scripts-timer-script-scheduled-script/83165/7 "2023-12-18T13:37:48Z")

</div>

> [@HelloWorld](#):
>
> Can I define and use functions inside def onScheduledEvent()

Can you? Yes, _should_ you? No.

Create the functions you need in a Script Library. Then the script in `onSchedultedEvent()` will be a single line call to some entry point into your function(s).
