# Tag Event Value Change Script triggering when it shouldn't

**URL:** <https://forum.inductiveautomation.com/t/tag-event-value-change-script-triggering-when-it-shouldnt/30409>\
**Category:** Ignition\
**Created:** [December 3, 2019, 4:00pm UTC](https://forum.inductiveautomation.com/t/tag-event-value-change-script-triggering-when-it-shouldnt/30409 "2019-12-03T16:00:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbranison](https://avatars.discourse-cdn.com/v4/letter/b/74df32/32.png) [@bbranison](https://forum.inductiveautomation.com/u/bbranison)\
**Post date:** [December 3, 2019, 4:00pm UTC](https://forum.inductiveautomation.com/t/tag-event-value-change-script-triggering-when-it-shouldnt/30409/1 "2019-12-03T16:00:07Z")

</div>

Greetings,  
I have a tag event triggering at unexpected times. The following tag event value change script is on an OPC tag. The tag history doesn’t show values that meet this condition. Any idea what could be causing the event?  
Thanks,  
Ben

if not (initialChange) and currentValue.quality.isGood() and previousValue.value \> 5 and currentValue.value \<= 5:  
system.tag.write("[.]…/…/HIP Q21/Run Trigger", 0)

|Dec 3, 2019 11:40 AM|3.98|  
|Dec 3, 2019 11:40 AM|4.05|  
|Dec 3, 2019 11:40 AM|4.13|  
|Dec 3, 2019 11:40 AM|4.21|  
|Dec 3, 2019 11:40 AM|4.29|  
|Dec 3, 2019 11:40 AM|4.37|  
|Dec 3, 2019 11:40 AM|4.44|  
|Dec 3, 2019 11:40 AM|4.52|  
|Dec 3, 2019 11:40 AM|4.6|  
|Dec 3, 2019 11:40 AM|4.68|  
|Dec 3, 2019 11:40 AM|4.75|  
|Dec 3, 2019 11:40 AM|4.83|  
|Dec 3, 2019 11:40 AM|4.91|  
|Dec 3, 2019 11:40 AM|4.99|  
|Dec 3, 2019 11:40 AM|5.07|  
|Dec 3, 2019 11:41 AM|5.14|  
|Dec 3, 2019 11:41 AM|5.22|  
|Dec 3, 2019 11:41 AM|5.3|  
|Dec 3, 2019 11:41 AM|5.3|  
|Dec 3, 2019 11:41 AM|5.43|  
|Dec 3, 2019 11:41 AM|5.5|  
|Dec 3, 2019 11:41 AM|5.57|  
|Dec 3, 2019 11:41 AM|5.64|  
|Dec 3, 2019 11:41 AM|5.7|  
|Dec 3, 2019 11:41 AM|5.77|  
|Dec 3, 2019 11:41 AM|5.84|

Thanks,  
Ben

---

<div class="post-metadata">

**Author:** ![ajdewhirst1](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@ajdewhirst1](https://forum.inductiveautomation.com/u/ajdewhirst1)\
**Post date:** [December 3, 2019, 4:43pm UTC](https://forum.inductiveautomation.com/t/tag-event-value-change-script-triggering-when-it-shouldnt/30409/2 "2019-12-03T16:43:14Z")

</div>

Looks like you need to indent the “system.tag.write…” line.

---

<div class="post-metadata">

**Author:** ![bbranison](https://avatars.discourse-cdn.com/v4/letter/b/74df32/32.png) [@bbranison](https://forum.inductiveautomation.com/u/bbranison)\
**Post date:** [December 3, 2019, 5:15pm UTC](https://forum.inductiveautomation.com/t/tag-event-value-change-script-triggering-when-it-shouldnt/30409/3 "2019-12-03T17:15:52Z")

</div>

I have it indented in the script. I just lost it in the copy/paste.

My problem is actually that the script is working when I don’t want it to.

---

<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:** [December 3, 2019, 5:28pm UTC](https://forum.inductiveautomation.com/t/tag-event-value-change-script-triggering-when-it-shouldnt/30409/4 "2019-12-03T17:28:28Z")

</div>

Try moving the first open paren in your if statement to before the `not` keyword.

Consider editing your post to include triple back-quotes on lines above and below your code to trigger proper formatting and highlighting. Like so:

```  
Some Code  
```

---

<div class="post-metadata">

**Author:** ![bbranison](https://avatars.discourse-cdn.com/v4/letter/b/74df32/32.png) [@bbranison](https://forum.inductiveautomation.com/u/bbranison)\
**Post date:** [December 5, 2019, 3:01pm UTC](https://forum.inductiveautomation.com/t/tag-event-value-change-script-triggering-when-it-shouldnt/30409/5 "2019-12-05T15:01:34Z")

</div>

Thanks for the heads up on the triple back quotes.

So instead of if not (initialChange) use if (notInitialChange) ?

---

<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:** [December 5, 2019, 3:11pm UTC](https://forum.inductiveautomation.com/t/tag-event-value-change-script-triggering-when-it-shouldnt/30409/6 "2019-12-05T15:11:45Z")

</div>

Yes, `(not initialChange)`. Note the space and exact case for initialChange.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 28, 2020, 1:24pm UTC](https://forum.inductiveautomation.com/t/tag-event-value-change-script-triggering-when-it-shouldnt/30409/7 "2020-05-28T13:24:46Z")

</div>

If you didn’t work this out, you’re using `.../` instead of `../` in your tag write. The former won’t work. Unless of course the forum replaced your two dots with three dots because you didn’t use preformatting…  
Unrelated side note, you should use preformatting for all of your code!  
e.g.

```auto
if not (initialChange) and currentValue.quality.isGood() and previousValue.value > 5 and currentValue.value <= 5:
	system.tag.write("[.]../../HIP Q21/Run Trigger", 0)

```
