# Tag Value (Change Event)

**URL:** <https://forum.inductiveautomation.com/t/tag-value-change-event/29447>\
**Category:** Ignition\
**Created:** [October 28, 2019, 2:41pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-event/29447 "2019-10-28T14:41:01Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcamp1](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@dcamp1](https://forum.inductiveautomation.com/u/dcamp1)\
**Post date:** [October 28, 2019, 2:41pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-event/29447/1 "2019-10-28T14:41:01Z")

</div>

I can’t figure out how to make this work.

I have a tag value that I don’t want to show a negative value, example -5.96.( I only want the positive!  
(Now I can correct in the PLC but I just thought until I can get to location I could fix in scada.)

I have tried adding a tag event script something like this.  
if Tag(Path) \< 0.00:  
Tag(Path) = 0.00

I get no errors for the script but it does not work.

Can someone point me in the right direction?

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [October 28, 2019, 2:54pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-event/29447/2 "2019-10-28T14:54:04Z")

</div>

You have a combination of scripting and [expression](https://docs.inductiveautomation.com/display/DOC80/Expression+Overview+and+Syntax) language there. You need [scripting](https://docs.inductiveautomation.com/display/DOC80/Gateway+Event+Scripts#GatewayEventScripts-TagChangeScripts).Try something like this:

```python
if event.getValue() < 0:
	system.tag.write(event.getTagPath().toString(), 0)

```

EDIT: Above was untested and isn't quite what you need; see:

> [@Tag Value (Change Event)](http://forum.inductiveautomation.com/t/tag-value-change-event/29447/8):
>
> Yes. And if it's writing back to itself, you don't need to include a tag path, just use the tagPath included in the event like this: if currentValue.value \< 0: system.tag.write(tagPath, 0) if not initialChange makes sense for most things, but it you never want this value to be zero there's no reason to exclude initialChange.

---

<div class="post-metadata">

**Author:** ![dcamp1](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@dcamp1](https://forum.inductiveautomation.com/u/dcamp1)\
**Post date:** [October 28, 2019, 4:14pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-event/29447/3 "2019-10-28T16:14:01Z")

</div>

Ok, I now have this and it still does not function in the Tag Change Event.

“”"  
if ("[.]Flow1 Rate").value \< 0.00:  
system.tag.write("[.]Flow1 Rate").value, 0.00  
“”"  
So I’m still needing some pointers

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [October 28, 2019, 4:28pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-event/29447/4 "2019-10-28T16:28:29Z")

</div>

You would need to use `system.tag.read()` on that first line to do it that way. But the tag value change event already includes the value accessible via `event.getValue()` so there’s no reason to do a tag read. Have you tried the script as I posted above?

Use the button shown in dark grey near top right of this screen clipping to properly format code (you were close!):  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/5/5c33918b23dc335cbf31216b98b4e8bdd3cb1159.png)

---

<div class="post-metadata">

**Author:** ![dcamp1](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@dcamp1](https://forum.inductiveautomation.com/u/dcamp1)\
**Post date:** [October 28, 2019, 4:46pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-event/29447/5 "2019-10-28T16:46:29Z")

</div>

Still not working.

 ![TagEventChange](https://us1.discourse-cdn.com/inductiveautomation/original/2X/5/5bdbe94f5abe2c65b1d694d75075237f977acf6b.jpeg)

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [October 28, 2019, 4:54pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-event/29447/6 "2019-10-28T16:54:00Z")

</div>

Use

```auto
if not initialChange and currentValue.value < 0.00:
	system.tag.write("[.]Flow1 Rate",0.00)

```

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [October 28, 2019, 4:58pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-event/29447/7 "2019-10-28T16:58:07Z")

</div>

Also make sure you actually change the tags value to trigger the event, for example change it from -4.5 to -5.5

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [October 28, 2019, 5:03pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-event/29447/8 "2019-10-28T17:03:05Z")

</div>

> [@MMaynard](#):
>
> Use
> 
> ```auto
> if not initialChange and currentValue.value < 0.00:
> system.tag.write("[.]Flow1 Rate",0.00)
> 
> ```

Yes. And if it's writing back to itself, you don't need to include a tag path, just use the `tagPath` included in the event like this:

```auto
if currentValue.value < 0:
	system.tag.write(tagPath, 0)

```

`if not initialChange` makes sense for most things, but it you never want this value to be zero there's no reason to exclude initialChange.

---

<div class="post-metadata">

**Author:** ![Rendi.Yohanes](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@Rendi.Yohanes](https://forum.inductiveautomation.com/u/Rendi.Yohanes)\
**Post date:** [October 29, 2019, 2:49pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-event/29447/9 "2019-10-29T14:49:49Z")

</div>

Just another perpsective.

If face with this problem, what I would do is I would rather create another tag.  
Then, in that new tag just write a simple expression max(0, old\_tag).

Something along that line.

---

<div class="post-metadata">

**Author:** ![dcamp1](https://avatars.discourse-cdn.com/v4/letter/d/dc4da7/32.png) [@dcamp1](https://forum.inductiveautomation.com/u/dcamp1)\
**Post date:** [October 29, 2019, 4:10pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-event/29447/10 "2019-10-29T16:10:17Z")

</div>

Thanks to everyone for all the help, examples, Ideas.

I never could it to work like I was hoping for, so I made a trip to location and fixed the code in the PLC, I should have done this to start.

Thanks again

---

<div class="post-metadata">

**Author:** ![mhamaker](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@mhamaker](https://forum.inductiveautomation.com/u/mhamaker)\
**Post date:** [November 2, 2019, 1:54pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-event/29447/11 "2019-11-02T13:54:11Z")

</div>

Hi!

If you’re using Ignition 8.0 you can do a transform with Expression like:

abs({value})

[https://docs.inductiveautomation.com/display/DOC80/Expression+Transform](https://docs.inductiveautomation.com/display/DOC80/Expression+Transform)

[https://docs.inductiveautomation.com/display/DOC80/abs](https://docs.inductiveautomation.com/display/DOC80/abs)

The same expression function exists in 7.9 but you would implement differently, if I recall correctly.

---

<div class="post-metadata">

**Author:** ![bmusson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmusson/32/87530_2.png) [@bmusson](https://forum.inductiveautomation.com/u/bmusson)\
**Post date:** [November 3, 2019, 1:12am UTC](https://forum.inductiveautomation.com/t/tag-value-change-event/29447/12 "2019-11-03T01:12:28Z")

</div>

You could also enable linear scaling on the tag to use the ‘Clamp Mode’ property. Set linear scaling with Raw = 0-100, Scaled = 0-100, and Clamp Mode = ‘Clamp\_Low’. It doesn’t really matter what the high raw/scale values are if you don’t enable high clamping.

---

<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:** [November 3, 2019, 7:46pm UTC](https://forum.inductiveautomation.com/t/tag-value-change-event/29447/13 "2019-11-03T19:46:16Z")

</div>

> [@dcamp1](#):
>
> I never could it to work like I was hoping for

That's because you were writing it back to itself. Every time the OPC driver supplied a new value, that would be propagated to subscribers, followed by the zero from the script. You would have to make a derived tag to hold the clamped value. The same race can occur in the PLC, too, if you are trying to overwrite the negatives in place. An OPC driver could read the negative just before the ladder replaced it. (Smaller race window in the PLC, though.)
