# Action script on a timer

**URL:** <https://forum.inductiveautomation.com/t/action-script-on-a-timer/62320>\
**Category:** Ignition\
**Created:** [July 26, 2022, 7:06pm UTC](https://forum.inductiveautomation.com/t/action-script-on-a-timer/62320 "2022-07-26T19:06:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin\_Szatkowski](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@Justin\_Szatkowski](https://forum.inductiveautomation.com/u/Justin_Szatkowski)\
**Post date:** [July 26, 2022, 7:06pm UTC](https://forum.inductiveautomation.com/t/action-script-on-a-timer/62320/1 "2022-07-26T19:06:28Z")

</div>

I currently have a large action script tied to a button press. I wish to also run the same code on a timer, say every hour. Is there a way to do this, while accessing the properties necessary within the button’s normal view?

---

<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:** [July 26, 2022, 7:07pm UTC](https://forum.inductiveautomation.com/t/action-script-on-a-timer/62320/2 "2022-07-26T19:07:53Z")

</div>

Move the code to a project library script, declaring function arguments for the items it needs. Replace the event code with a one-line function call, supplying the needed arguments. Use that same function call in the other event.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [July 26, 2022, 7:24pm UTC](https://forum.inductiveautomation.com/t/action-script-on-a-timer/62320/3 "2022-07-26T19:24:05Z")

</div>

As a workflow practice I highly recommend to get in the habit of writing all your business logic scripts in the project library first and then _calling_ them from the appropriate spots. Helps keep your code DRY and also lets you look at all the logic surrounding an entity in your system in a single place which can be very helpful for troubleshooting or when you come back to it months later.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 27, 2022, 7:16am UTC](https://forum.inductiveautomation.com/t/action-script-on-a-timer/62320/4 "2022-07-27T07:16:16Z")

</div>

> [@Justin\_Szatkowski](#):
>
> while accessing the properties necessary within the button’s normal view?

No, I don't think so. A timer script will not know anything about your button's view.

Now, if those properties should be accessible to a timer script, then this probably means that they should not be in a view. There's a scope issue somewhere.  
There are several places where they could be set instead, depending on what they are and what they're used for: session custom properties, tags, database...
