# Scheduled Gateway Event / on Demand

**URL:** <https://forum.inductiveautomation.com/t/scheduled-gateway-event-on-demand/75211>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [June 19, 2023, 1:58pm UTC](https://forum.inductiveautomation.com/t/scheduled-gateway-event-on-demand/75211 "2023-06-19T13:58:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [June 19, 2023, 1:58pm UTC](https://forum.inductiveautomation.com/t/scheduled-gateway-event-on-demand/75211/1 "2023-06-19T13:58:49Z")

</div>

I have a Gateway Event Script Set to run twice a Day. Is there a way to manually force this script to run by user input without having a second copy of the script?

What I want is for the script to run twice a day or whatever I set the schedule for, but also to run a single time with user input (button click), but not have the script in 2 different places.

---

<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:** [June 19, 2023, 2:26pm UTC](https://forum.inductiveautomation.com/t/scheduled-gateway-event-on-demand/75211/2 "2023-06-19T14:26:45Z")

</div>

Put the logic in a project script. Then call the project script from the gateway event to invoke it on your twice-a-day schedule or from a button when needed on-demand.

---

<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:** [June 19, 2023, 3:27pm UTC](https://forum.inductiveautomation.com/t/scheduled-gateway-event-on-demand/75211/3 "2023-06-19T15:27:25Z")

</div>

> [@dkhayes117](#):
>
> Put the logic in a project script.

This, always. While you **can** write entire scripts in the dialog for your event, you should not. For best maintainability, and for other uses, event scripts should be one-liners that just pass all the relevant event information to a project library script.

---

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [June 19, 2023, 4:11pm UTC](https://forum.inductiveautomation.com/t/scheduled-gateway-event-on-demand/75211/4 "2023-06-19T16:11:11Z")

</div>

I have the script put in project library and Scheduled event to call it. If I want a button to call it would the best way be to screen button --\> changes tag [RunXScriptTag] then have gateway tag change script monitor [RunXScriptTag] to call the function instead of having the screen button calling the function directly?

---

<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:** [June 19, 2023, 4:59pm UTC](https://forum.inductiveautomation.com/t/scheduled-gateway-event-on-demand/75211/5 "2023-06-19T16:59:17Z")

</div>

No, if you go through a tag, then your clients aren't independent. Just call the script from the button.

---

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [June 19, 2023, 5:19pm UTC](https://forum.inductiveautomation.com/t/scheduled-gateway-event-on-demand/75211/6 "2023-06-19T17:19:08Z")

</div>

> [@pturmel](#):
>
> t inde

I tried that at first but it locked up the client. Script is quite large, checking a DB table against tag values and correcting if needed. Takes about 2 min to run if no changes and can be much longer if it finds and corrects errors. I don't need more then 1 client to run it at any time. This is an administration level operation so the "button" would be restricted access and rarely used.

---

<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:** [June 19, 2023, 5:26pm UTC](https://forum.inductiveautomation.com/t/scheduled-gateway-event-on-demand/75211/7 "2023-06-19T17:26:38Z")

</div>

> [@rfolkes](#):
>
> I tried that at first but it locked up the client

Run it on a background thread using `system.util.invokeAsyncornous()` and `system.util.invokeLater()` if needed.

There are multiple posts on the forum on how to accomplish that.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 19, 2023, 5:28pm UTC](https://forum.inductiveautomation.com/t/scheduled-gateway-event-on-demand/75211/8 "2023-06-19T17:28:42Z")

</div>

Or `system.util.sendMessage` to run it on the gateway. Add some locking/exclusivity in the message handler before actually invoking the slow code.
