# Write a script that runs the first of each month at midnight - how?

**URL:** <https://forum.inductiveautomation.com/t/write-a-script-that-runs-the-first-of-each-month-at-midnight-how/22267>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [January 31, 2019, 7:48pm UTC](https://forum.inductiveautomation.com/t/write-a-script-that-runs-the-first-of-each-month-at-midnight-how/22267 "2019-01-31T19:48:53Z")\
**Posts on this page:** 8\
**Page:** 1

<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:** [January 31, 2019, 7:48pm UTC](https://forum.inductiveautomation.com/t/write-a-script-that-runs-the-first-of-each-month-at-midnight-how/22267/1 "2019-01-31T19:48:54Z")

</div>

I want to run a very simple script that helps keep our database healthy, once a month on the first of each month at midnight. It is NOT important that it happens at midnight to the millisecond, however, it should most definitely run around that time within reason.

The script is going to call an already made stored procedure, so it should be short and simple, I imagine like this -

```auto
import system
system.db.runQuery("CALL sp_dbmaint())")

```

I just don’t know where I should be putting this or how to get it to trigger on the first of every month. Thoughts?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [January 31, 2019, 10:07pm UTC](https://forum.inductiveautomation.com/t/write-a-script-that-runs-the-first-of-each-month-at-midnight-how/22267/2 "2019-01-31T22:07:22Z")

</div>

Perhaps overly simplistic, but you could create an expression tag using:

```auto
getDayOfMonth(now())

```

Then, with a Value Changed event on the tag:

```python
	if currentValue.value == 1:
      import system
      system.db.runQuery("CALL sp_dbmaint())")

```

It should execute once on the first day of the month (The midnight is implied).

---

<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:** [February 1, 2019, 2:25pm UTC](https://forum.inductiveautomation.com/t/write-a-script-that-runs-the-first-of-each-month-at-midnight-how/22267/3 "2019-02-01T14:25:32Z")

</div>

Works for me, it’s what my coworkers suggested too. I just thought maybe Ignition would have some built in “run script X at time Y” feature but I couldn’t find anything like that. Timer was close but not exactly what I needed. Thanks.

---

<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:** [February 1, 2019, 6:18pm UTC](https://forum.inductiveautomation.com/t/write-a-script-that-runs-the-first-of-each-month-at-midnight-how/22267/4 "2019-02-01T18:18:11Z")

</div>

There was an item on the ideas portal for ignition, but I can’t find it. That system has been moved to a facebook platform, and I can’t see any of it.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 1, 2019, 6:31pm UTC](https://forum.inductiveautomation.com/t/write-a-script-that-runs-the-first-of-each-month-at-midnight-how/22267/5 "2019-02-01T18:31:38Z")

</div>

I think this was it:

[https://ideas.inductiveautomation.com/ignition-features-and-ideas/p/add-scheduled-triggering-of-custom-actionsevents](https://ideas.inductiveautomation.com/ignition-features-and-ideas/p/add-scheduled-triggering-of-custom-actionsevents)

---

<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:** [February 1, 2019, 6:35pm UTC](https://forum.inductiveautomation.com/t/write-a-script-that-runs-the-first-of-each-month-at-midnight-how/22267/6 "2019-02-01T18:35:19Z")

</div>

Yes, that’s it. I can’t log into it anymore – seems to due to a reference to [facebook.net](http://facebook.net). Facebook addresses are blocked at every router I own or control.

---

<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:** [February 1, 2019, 8:38pm UTC](https://forum.inductiveautomation.com/t/write-a-script-that-runs-the-first-of-each-month-at-midnight-how/22267/7 "2019-02-01T20:38:21Z")

</div>

Actually this is not working at all. I’ve tried it with `system.db.runQuery` and with

```auto
call = system.db.createSProcCall("sp_dbmaint", database="AntiDLocale")
system.db.execSProcCall(call)

```

Any idea why it’s not working? I added the tag under the main `Tags` folder. I want this to run regardless of if a cilent is open.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 1, 2019, 9:22pm UTC](https://forum.inductiveautomation.com/t/write-a-script-that-runs-the-first-of-each-month-at-midnight-how/22267/8 "2019-02-01T21:22:15Z")

</div>

My goof! Replace _ **currentValue** _ with _ **currentValue.value** _

I’ll admit it. I forget this three or four times a year. 😊

**currentValue** is a “qualified value”, so it has value, quality, and timestamp info.
