# Changing Tag Values Using Button to Activate Tag Event Scripting

**URL:** <https://forum.inductiveautomation.com/t/changing-tag-values-using-button-to-activate-tag-event-scripting/97023>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [October 9, 2024, 2:06pm UTC](https://forum.inductiveautomation.com/t/changing-tag-values-using-button-to-activate-tag-event-scripting/97023 "2024-10-09T14:06:45Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@Joe\_Alcide](https://forum.inductiveautomation.com/u/Joe_Alcide)\
**Post date:** [October 9, 2024, 2:06pm UTC](https://forum.inductiveautomation.com/t/changing-tag-values-using-button-to-activate-tag-event-scripting/97023/1 "2024-10-09T14:06:45Z")

</div>

Hi! I want to be able to change a bunch of tags values using a button. Doesn't matter the number, just need the values to change to activate a bunch of tag event scripts. What would be the best way to do this? Can I use some kind of random int function? Is there something else that would work better? Any help would be appreciated, thanks!

---

<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:** [October 9, 2024, 2:15pm UTC](https://forum.inductiveautomation.com/t/changing-tag-values-using-button-to-activate-tag-event-scripting/97023/2 "2024-10-09T14:15:18Z")

</div>

> [@Joe\_Alcide](#):
>
> activate a bunch of tag event scripts

1. Are these value change scripts, or Gateway Tag Change scripts?
2. Is each script specific to that particular tag?

The fact that you are asking this question makes me think that the scripts don't actually belong in a Tag Change event of any kind, but rather should be in the Library (there is an argument that they should be there anyway) so that you can just call the scripts natively.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 9, 2024, 2:18pm UTC](https://forum.inductiveautomation.com/t/changing-tag-values-using-button-to-activate-tag-event-scripting/97023/3 "2024-10-09T14:18:53Z")

</div>

Use a script and [https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-writeBlocking](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-writeBlocking) to write out the current millisecond value from [system.date.now | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-date/system-date-now). Use modulo division to return the last three digits (or whatever you want).  
`x = system.date.now() % 1000`  
should do the trick.

---

<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:** [October 9, 2024, 2:24pm UTC](https://forum.inductiveautomation.com/t/changing-tag-values-using-button-to-activate-tag-event-scripting/97023/4 "2024-10-09T14:24:04Z")

</div>

> [@lrose](#):
>
> so that you can just call the scripts natively

This, with the caveat that if calling from Vision, you may need to use a message handler to run in gateway scope. (Or use my `@system.util.runInGateway` decorator.)

---

<div class="post-metadata">

**Author:** ![Joe\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@Joe\_Alcide](https://forum.inductiveautomation.com/u/Joe_Alcide)\
**Post date:** [October 9, 2024, 2:32pm UTC](https://forum.inductiveautomation.com/t/changing-tag-values-using-button-to-activate-tag-event-scripting/97023/5 "2024-10-09T14:32:24Z")

</div>

Value change scripts, the scripts are unique to each tag. Using "Trigger tags" to activate the value change tag event scripts. Where is this library where you think I should place these scripts in? Also, is there a way I can set the rate at which these scripts run then? Like once every hour?

---

<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:** [October 9, 2024, 2:34pm UTC](https://forum.inductiveautomation.com/t/changing-tag-values-using-button-to-activate-tag-event-scripting/97023/6 "2024-10-09T14:34:24Z")

</div>

> [@Joe\_Alcide](#):
>
> Like once every hour?

So, expensive scripts? Such should never be tag `valueChange` event scripts anyways. Use gateway events of whatever type is most appropriate. (Probably a **scheduled** event.) (Put the bulk of the code in a project library script function.)

Both of these are under the "Scripting" section of the designer navigation tree.

---

<div class="post-metadata">

**Author:** ![Joe\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@Joe\_Alcide](https://forum.inductiveautomation.com/u/Joe_Alcide)\
**Post date:** [October 9, 2024, 2:57pm UTC](https://forum.inductiveautomation.com/t/changing-tag-values-using-button-to-activate-tag-event-scripting/97023/7 "2024-10-09T14:57:57Z")

</div>

Should I use Client or Gateway Event Timer Scripts you think?

---

<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:** [October 9, 2024, 3:00pm UTC](https://forum.inductiveautomation.com/t/changing-tag-values-using-button-to-activate-tag-event-scripting/97023/8 "2024-10-09T15:00:03Z")

</div>

> [@Joe\_Alcide](#):
>
> the scripts are unique to each tag

Like they use the current value of that tag, or each tag runs a specific script? Sorry, just trying to grasp what is happening.

> [@Joe\_Alcide](#):
>
> Should I use Client or Gateway Event Timer Scripts you think?

Does it need to happen only when a client is running? Does it need to happen for each client that is running?

Generally, I would probably use a Gateway Event. Also note that Timer scripts are not guaranteed to happen at a set interval (e.g. at the top of every hour).

---

<div class="post-metadata">

**Author:** ![Joe\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@Joe\_Alcide](https://forum.inductiveautomation.com/u/Joe_Alcide)\
**Post date:** [October 9, 2024, 3:03pm UTC](https://forum.inductiveautomation.com/t/changing-tag-values-using-button-to-activate-tag-event-scripting/97023/9 "2024-10-09T15:03:38Z")

</div>

Each tag runs a specfic script. So I think it would make more sense to put them all in as Gateway Event Timer Scripts. Needs to run in the specific client, not for each client, so maybe client event scripts make more sense. Sorry, I was taught to use the tag event scripting when I first was learning ignition. Didn't even know these things existed. 🥲

---

<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:** [October 9, 2024, 3:08pm UTC](https://forum.inductiveautomation.com/t/changing-tag-values-using-button-to-activate-tag-event-scripting/97023/10 "2024-10-09T15:08:59Z")

</div>

> [@Joe\_Alcide](#):
>
> Needs to run in the specific client

What does this mean? Are you using client tags? Why are they specific to a client?

> [@Joe\_Alcide](#):
>
> I was taught to use the tag event scripting when I first was learning ignition

Tag Value Change scripts have their place for sure, but there are restrictions to what you can do there. For instance, they run in a fixed thread pool (three IIRC), and if you exceed that you can miss events. Best practice says that they should execute in single digit milliseconds, and you should basically never touch a database.

---

<div class="post-metadata">

**Author:** ![Joe\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@Joe\_Alcide](https://forum.inductiveautomation.com/u/Joe_Alcide)\
**Post date:** [October 9, 2024, 3:18pm UTC](https://forum.inductiveautomation.com/t/changing-tag-values-using-button-to-activate-tag-event-scripting/97023/11 "2024-10-09T15:18:36Z")

</div>

Its specific to a project im in. I put one of my tag event scripts on the gateway events timer. Hasn't ran once yet and havent gotten anything on timer or wrapper log file... What's going on?

---

<div class="post-metadata">

**Author:** ![Joe\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@Joe\_Alcide](https://forum.inductiveautomation.com/u/Joe_Alcide)\
**Post date:** [October 9, 2024, 3:29pm UTC](https://forum.inductiveautomation.com/t/changing-tag-values-using-button-to-activate-tag-event-scripting/97023/12 "2024-10-09T15:29:17Z")

</div>

Found an error in the script console. No idea what the second half means. Script should be fine. Just ran it by changing the value on the original tag event script. Need help.

```python

>>> ImportError: Cannot import site module and its dependencies: Error loading module LOCAP_PD_Trigger: AttributeError: 'NoneType' object has no attribute 'strip'
Determine if the following attributes are correct:
  * sys.path: [C:\Users\mmm\.ignition\cache\gwlocalhost_8088\C0\pylib, C:\Users\**\.ignition\cache\resources\platform\jython-ia-2.7.2.1.jar\00000000A5AE7F4C\Lib, __classpath__ , __pyclasspath__ /]
    This attribute might be including the wrong directories, such as from CPython
  * sys.prefix: C:\Users\NOTGIVINGAWAY\.ignition\cache\resources\platform\jython-ia-2.7.2.1.jar\00000000A5AE7F4C
    This attribute is set by the system property python.home, although it can
    be often automatically determined by the location of the Jython jar file

You can use the -S option or python.import.site=false to not import the site module

```

---

<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:** [October 9, 2024, 3:34pm UTC](https://forum.inductiveautomation.com/t/changing-tag-values-using-button-to-activate-tag-event-scripting/97023/13 "2024-10-09T15:34:11Z")

</div>

> [@Joe\_Alcide](#):
>
> Its specific to a project im in

Okay, so a little explanation.

Client Event Scripts are specific to vision, and are project resource, but they are run independently for _each_ running client. They are useful for things that you want to occur for every running client, but the result may be different based on the context provided by that client.

> **[Client Event Scripts | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/ignition-modules/vision/scripting-in-vision/client-event-scripts)**
>
> Client Event Scripts Overview

Gateway Event Scripts are also project resources, however, they are not specific to any module and will run regardless of if there is a client running or not. Once you have created one, a project must be _saved_ before that script will begin execution.

> **[Gateway Event Scripts | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/platform/scripting/scripting-in-ignition/gateway-event-scripts#gateway-event-scripts-overview)**
>
> Gateway Event Scripts Overview

Timer scripts execute periodically at a fixed delay or rate. If set for a fixed delay then it will wait for that delay between each execution. So if you have a fixed delay of 1 sec and your script takes 5 secs to run, then your script will execute once every 6 seconds. If they are set for Fixed rate then they attempt to run at a fixed rate relative to the first execution, which means when it starts matters, so the time the script occurs will be influenced by things like Gateway restarts, background processes and other things.

[Gateway Timer Event Scripts](https://docs.inductiveautomation.com/docs/8.1/platform/scripting/scripting-in-ignition/gateway-event-scripts#timer-script)

If you need the script to occur at a specific time, then a scheduled event is a better fit.

[Gateway Scheduled Scripts](https://docs.inductiveautomation.com/docs/8.1/platform/scripting/scripting-in-ignition/gateway-event-scripts#gateway-scheduled-scripts)

I would say that these scripts should absolutely be in the script library and be called from a Gateway Event.

> [@Joe\_Alcide](#):
>
> Just ran it by changing the value on the original tag event script. Need help.

Scripts run in tags value changed events run in Gateway Scope, scripts run in the Script Console run in Vision Client Scope. This means that things which exist for the script in one place may not be present in the other. The Script Console should not be used for testing scripts that will run in a Gateway scope.

I would need to see the script to be certain, but it looks like it is trying to import a python library that is available on the gateway server, but isn't available on the machine you are running the script console on.

---

<div class="post-metadata">

**Author:** ![Joe\_Alcide](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@Joe\_Alcide](https://forum.inductiveautomation.com/u/Joe_Alcide)\
**Post date:** [October 9, 2024, 3:42pm UTC](https://forum.inductiveautomation.com/t/changing-tag-values-using-button-to-activate-tag-event-scripting/97023/14 "2024-10-09T15:42:03Z")

</div>

Thanks!
