# Runscript() alternative

**URL:** <https://forum.inductiveautomation.com/t/runscript-alternative/45274>\
**Category:** Ignition\
**Tags:** vision, ignition80\
**Created:** [April 5, 2021, 6:05pm UTC](https://forum.inductiveautomation.com/t/runscript-alternative/45274 "2021-04-05T18:05:41Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [April 5, 2021, 6:05pm UTC](https://forum.inductiveautomation.com/t/runscript-alternative/45274/1 "2021-04-05T18:05:41Z")

</div>

The later versions, post 8.1.1, look to have major issues wit tag() and runscript(). I have done away with tag() references, and all but one runscript() reference. What are my options for using runsciprt() for system.alarm.queryStatus on a 1 second update? I was thinking of dropping a timer, but figured someone might have a better way.

---

<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:** [April 5, 2021, 6:23pm UTC](https://forum.inductiveautomation.com/t/runscript-alternative/45274/2 "2021-04-05T18:23:18Z")

</div>

Don’t use runScript() for anything that takes more than a tiny fraction of a second. (If using Vision, that means anything that calls out to the gateway). Anything longer should be run in a gateway timer event and delivered by tag or message, or in Vision, run in an asynchronous thread with results delivered with invokeLater.

Yes, you _can_ get away with breaking this general run in small, simple applications. Don’t do it.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [April 5, 2021, 6:29pm UTC](https://forum.inductiveautomation.com/t/runscript-alternative/45274/3 "2021-04-05T18:29:29Z")

</div>

I used runscript for:

1. system.tag.exists
2. system.alarm.queryStatus

For #1 those were easy enough to fix, just place in a window open script, they only ran once anyways.  
For #2, this needs to update on a regular basis. These are dynamic popups so gateway timers are not an option. So what would you recommend for that?

---

<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:** [April 5, 2021, 6:34pm UTC](https://forum.inductiveautomation.com/t/runscript-alternative/45274/4 "2021-04-05T18:34:55Z")

</div>

Is this Vision or Perspective?

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [April 5, 2021, 6:45pm UTC](https://forum.inductiveautomation.com/t/runscript-alternative/45274/5 "2021-04-05T18:45:20Z")

</div>

Vision

---

<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:** [April 5, 2021, 6:46pm UTC](https://forum.inductiveautomation.com/t/runscript-alternative/45274/6 "2021-04-05T18:46:23Z")

</div>

Then use a client timer event to start an asynchronous thread, and report the results to a client tag.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [April 5, 2021, 7:43pm UTC](https://forum.inductiveautomation.com/t/runscript-alternative/45274/7 "2021-04-05T19:43:14Z")

</div>

Yeah, I’m obviously not explaining myself well. I’ll throw a timer on the window for now.

---

<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:** [April 5, 2021, 7:46pm UTC](https://forum.inductiveautomation.com/t/runscript-alternative/45274/8 "2021-04-05T19:46:17Z")

</div>

A timer’s actionPerformed event runs on the GUI thread, too. If you go this route (nothing wrong with a timer component instead of a timer event), you still need to make the call to queryAlarmStatus from a **background** thread. The timer component can launch one with invokeAsynchronous.

The problem isn’t that runScript itself is a problem, but that calling slow functions from the GUI thread is a problem. And runScript uses the GUI thread.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [April 5, 2021, 8:01pm UTC](https://forum.inductiveautomation.com/t/runscript-alternative/45274/9 "2021-04-05T20:01:17Z")

</div>

> [@pturmel](#):
>
> The problem isn't that runScript itself is a problem,

Yes it is! There is a bug introduced sometime after 8.1.1, I have been through this with IA.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [April 6, 2021, 10:16pm UTC](https://forum.inductiveautomation.com/t/runscript-alternative/45274/10 "2021-04-06T22:16:39Z")

</div>

Do you have the ticket number? I can’t find an existing ticket that seems remotely similar. Thanks!

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [April 7, 2021, 12:41am UTC](https://forum.inductiveautomation.com/t/runscript-alternative/45274/11 "2021-04-07T00:41:21Z")

</div>

No. I asked several times for it. Aaron Palas is the one working on it. He did respond today stating he isn’t able to replicate on his end. I gave him a project to work with and did a remote session so he could see for himself.

It’s very easy for me to replicate. I had a well working project in 8.1.1. Upgrade to 8.1.2/3/4, and popups are insanely slow to open, about 3-4 seconds longer. Once I removed all runscript(), they were basically back to normal, maybe a bit faster.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 7, 2021, 1:04am UTC](https://forum.inductiveautomation.com/t/runscript-alternative/45274/12 "2021-04-07T01:04:24Z")

</div>

Whatever the problem turns out to be it isn’t going to be `runScript` itself, rather it’s going to be whatever you’re executing inside the `runScript` that is behaving differently.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [April 7, 2021, 1:53am UTC](https://forum.inductiveautomation.com/t/runscript-alternative/45274/13 "2021-04-07T01:53:40Z")

</div>

Perhaps, but the same code running from the runscript is still executing, just in other ways, window event or timer event for the instance that needs to run continuously. So based on that, it’s hard to agree with you. Like I said, I’ve given the project to support to look at it. Works fine in 8.1.1, later versions it doesn’t. Whatever the problem, it doesn’t matter to me, I just would like to figure out what the problem is.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 7, 2021, 2:37am UTC](https://forum.inductiveautomation.com/t/runscript-alternative/45274/14 "2021-04-07T02:37:24Z")

</div>

I left a note on the ticket for the support rep suggesting this but I’ll tell you directly as well: it might be interesting to set the logger “alarm.StateModel.Query” to DEBUG level and then open the slow windows/popups and check the gateway logs to see what alarm status queries are being executed and how long they’re taking. Comparing these logs between 8.1.1 and 8.1.2 may show something interesting.

I’m focused on alarm status queries because a number of your thread dumps from 8.1.2 clearly show alarm status queries invoked from `runScript` on the UI thread. I don’t know how this wasn’t already an issue for you regardless of what version you were on. I can only guess the queries are now returning slower for some reason.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [April 7, 2021, 9:38am UTC](https://forum.inductiveautomation.com/t/runscript-alternative/45274/15 "2021-04-07T09:38:16Z")

</div>

Thank you for digging into this and for the tips.
