# Execution of scripting in tag's value change

**URL:** <https://forum.inductiveautomation.com/t/execution-of-scripting-in-tags-value-change/90168>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [May 9, 2024, 3:24pm UTC](https://forum.inductiveautomation.com/t/execution-of-scripting-in-tags-value-change/90168 "2024-05-09T15:24:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jakub\_R](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@Jakub\_R](https://forum.inductiveautomation.com/u/Jakub_R)\
**Post date:** [May 9, 2024, 3:24pm UTC](https://forum.inductiveautomation.com/t/execution-of-scripting-in-tags-value-change/90168/1 "2024-05-09T15:24:22Z")

</div>

Hi,  
I had a question about running script in tag's value change. We have some application working in production, that is critical for line to work. I don't think it is a good practice, but this is how our system has been designed, and we just adapted it in the new factory. We recently had a lot of troubles with errors that accure from script in value change not finishing in time (first line of script checks if the value is 1 and then sets a acknowlage tag to true, which should happen every time, but it fails sometimes even tho the value of that tag is changing). So I wanted to know, if every tag that has a script running when value changes is put in the same queue to execute - that would explain those scripts not working sometimes. If thats the case, is there a way to prioritize running a specific UDT/scan class scripts?  
Also what is the best way to save OPC tags values to database? We have recently added a lot of system.db.runUpdate/PrepQuery funcitions on tag scripts, that save desired parameters to our DB. They do it every hour, and those problems we have been having are mostly accuring on full hours (so when the insert to DB happens). We have disabled those tags for now and will monitor if we still get the error, but im pretty sure them not executing because of too many scripts running is the anserw.

---

<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:** [May 9, 2024, 3:30pm UTC](https://forum.inductiveautomation.com/t/execution-of-scripting-in-tags-value-change/90168/2 "2024-05-09T15:30:54Z")

</div>

> [@Jakub\_R](#):
>
> same queue to execute

Yes. And the scheduler has three threads. You **must** arrange for value change scripts to execute **very** quickly, preferably single digit milliseconds. If you must write to tags within a value change script, be sure to use `system.tag.writeAsync()`, not `system.tag.writeBlocking()`.

> [@Jakub\_R](#):
>
> way to prioritize

No.

> [@Jakub\_R](#):
>
> added a lot of system.db.runUpdate/PrepQuery

Absolutely deadly to the proper functioning of your system. Such calls that typically need network activity **must** use gateway tag change events (in a project), **not** tag value change scripts.

(Although you can safely use the Store and Forward versions to queue Updates or Inserts.)

---

<div class="post-metadata">

**Author:** ![Jakub\_R](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@Jakub\_R](https://forum.inductiveautomation.com/u/Jakub_R)\
**Post date:** [May 9, 2024, 3:47pm UTC](https://forum.inductiveautomation.com/t/execution-of-scripting-in-tags-value-change/90168/3 "2024-05-09T15:47:03Z")

</div>

Thank you @pturmel

Is there anyway to check that scheduler queue/previously run scripts?

I will remake my DB inserts to be exectued by gateway tag change event. If I have a working script in tag value change will it be the same script in gateway tag change event? I'm not sure how to read tag values in gateway script, I'm guessing its the same just wanted to make sure.

Also, when using scripts on components (like focus gained or action preformed), does that script execution share queue with scheduler for tag value change?

---

<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:** [May 9, 2024, 3:48pm UTC](https://forum.inductiveautomation.com/t/execution-of-scripting-in-tags-value-change/90168/4 "2024-05-09T15:48:34Z")

</div>

> [@Jakub\_R](#):
>
> anyway to check that scheduler queue

Not that I'm aware of.

> [@Jakub\_R](#):
>
> If I have a working script in tag value change will it be the same script in gateway tag change event?

Not quite. The values handed to a gateway tag change event are slightly different from a tag's value change event. But close.

> [@Jakub\_R](#):
>
> read tag values

Same.
