# Value Change Scripting

**URL:** <https://forum.inductiveautomation.com/t/value-change-scripting/33123>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [March 16, 2020, 3:13pm UTC](https://forum.inductiveautomation.com/t/value-change-scripting/33123 "2020-03-16T15:13:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![yifeiliu08](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@yifeiliu08](https://forum.inductiveautomation.com/u/yifeiliu08)\
**Post date:** [March 16, 2020, 3:13pm UTC](https://forum.inductiveautomation.com/t/value-change-scripting/33123/1 "2020-03-16T15:13:27Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/e/ec62c5f85751701ab569bd6ca222405281cd60ad.png)  
i have a memory Boolean tag, in it’s tag’s value change scripting i write the logic  
but if i change the tag from 0 to 1 and 1 to 0, i see there are nothing happened and output console is empty  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6095b8759a55689c128060c67e32dc0d86a0c9d6.png)

but if i designer a client tag the same scripting

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/8054e9421602b5862e533cd789eace299ae40a94.png)

it will works.

then i do a test

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/fc4ca79746ab724b91a3baf58b5772a00c84cb31.png)

i manually trigger the value change

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/a/a7c8b968eff5c09f2a17a6cc9483fa11f5b2173f.png)  
still no out put in the ouput, i don’t know why?

---

<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:** [March 16, 2020, 3:44pm UTC](https://forum.inductiveautomation.com/t/value-change-scripting/33123/2 "2020-03-16T15:44:53Z")

</div>

Tag events run in the gateway. The gateway cannot print to your designer or to any client. The gateway prints to the wrapper log. Are you sure it isn’t working?

---

<div class="post-metadata">

**Author:** ![osolorzano](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/osolorzano/32/6432_2.png) [@osolorzano](https://forum.inductiveautomation.com/u/osolorzano)\
**Post date:** [March 16, 2020, 6:37pm UTC](https://forum.inductiveautomation.com/t/value-change-scripting/33123/3 "2020-03-16T18:37:00Z")

</div>

To add to what pturmel said, `print()` won’t print to the gateway logs in the Status \> Logs webpage. For that you should use [system.util.getLogger()](https://docs.inductiveautomation.com/display/DOC80/system.util.getLogger)

---

<div class="post-metadata">

**Author:** ![yifeiliu08](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@yifeiliu08](https://forum.inductiveautomation.com/u/yifeiliu08)\
**Post date:** [March 17, 2020, 4:49am UTC](https://forum.inductiveautomation.com/t/value-change-scripting/33123/4 "2020-03-17T04:49:59Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/5/5a316e5513044968f67d0cb5184fd04cfb18744b.png)  
i have do a test one tag one in the client tag, and another in the normal tag group  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/b/bd941e3d2a5d804942e61a1b5df21d4e712ef4ea.png)  
both of them use the same logic

if i trigger the Client tag, test from 0-1 and 1-0 it will works  
but if i trigger the normal tag test from 0-1 and 1-0 it will not work.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/82910846cebf17818dc68e7c726604e897aa790d.png)  
gateway log will popup a lot info every second, i found found anything useful to my test tag value change case.

there tag path is  
[client]NT Log 4/test  
[HTC\_MANTIS]NTLogSystem/runScreen/test

---

<div class="post-metadata">

**Author:** ![yifeiliu08](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@yifeiliu08](https://forum.inductiveautomation.com/u/yifeiliu08)\
**Post date:** [March 17, 2020, 5:56am UTC](https://forum.inductiveautomation.com/t/value-change-scripting/33123/5 "2020-03-17T05:56:13Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/5/5d9c40146d6ace92feaba94c43a55086917fb5f5.png)  
i have try this scripting in a button then it works in the console with the ignition manual sample code  
but i don’t know how to integrate they scripting into value change, can you help to give me a sample code

---

<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:** [March 17, 2020, 1:00pm UTC](https://forum.inductiveautomation.com/t/value-change-scripting/33123/6 "2020-03-17T13:00:27Z")

</div>

Click the magnifying glass on one of those errors and examine the stack trace. The visible text in the screenshot suggests you are not getting the data you think in the event.

Please cut and paste the text of the complete error here. Places lines with triple back-quotes (these: ```) above and below the pasted text to make it readable.

Screenshots are not optimal.

We know that your logic is identical for both client tag and gateway tag. Client context and gateway context have substantial differences–some stuff simply isn’t available without a GUI, and the gateway doesn’t have one. Many people struggle with assumptions about what they think _should_ work in the gateway, without looking at the _documented_ differences.

---

<div class="post-metadata">

**Author:** ![yifeiliu08](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@yifeiliu08](https://forum.inductiveautomation.com/u/yifeiliu08)\
**Post date:** [March 17, 2020, 2:46pm UTC](https://forum.inductiveautomation.com/t/value-change-scripting/33123/7 "2020-03-17T14:46:11Z")

</div>

Dear Sir  
as you mentioned , tag events run in the gateway

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/e/e7ff8f6df38bbcbb49be97659cb8339fdb778fdf.png)  
then i check the gateway scripting manual , copy and paste the same logic ,it works perfect, i think , if i put all the tag change scripting in the gateway it will be easy for me to manager the project in the future

thanks a lot

---

<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:** [March 17, 2020, 2:50pm UTC](https://forum.inductiveautomation.com/t/value-change-scripting/33123/8 "2020-03-17T14:50:16Z")

</div>

You have errors in your gateway log that say what your problem is. Examine those errors' details to figure out your problem

> [@yifeiliu08](#):
>
> copy and paste the same logic ,it works perfect, i think

Clearly, due to the errors you are receiving, it does _ **not** _ work perfect.

---

<div class="post-metadata">

**Author:** ![yifeiliu08](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@yifeiliu08](https://forum.inductiveautomation.com/u/yifeiliu08)\
**Post date:** [March 18, 2020, 2:03am UTC](https://forum.inductiveautomation.com/t/value-change-scripting/33123/9 "2020-03-18T02:03:34Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/7d9ef343d986e6f4bfdb704491d7b8ef83b98ced.png)  
DEAR [pturmel](http://forum.inductiveautomation.com/u/pturmel)  
i check the log document, i found that tag, and found one tag expression issue make there are a lot of pop up infomation.

the expression logic is  
toStr(addHours(toDate({[.]EndDateAndTime}),-8))

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/f6748aecf129115df9ebc0bddcffad8ee48cd6e6.png)  
due to the blue line highlighted opc-tag is power off, so that make the expression tag(red line highlighted) popup a lot of warning, so , do you have suggestion , how to optimize the tag expression.

---

<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:** [March 18, 2020, 11:32am UTC](https://forum.inductiveautomation.com/t/value-change-scripting/33123/10 "2020-03-18T11:32:24Z")

</div>

Consider nesting the `try()` expression function (or the `coalesce()` function) in that expression to substitute a valid date when the source is not valid.
