# Tag change oldvalue

**URL:** <https://forum.inductiveautomation.com/t/tag-change-oldvalue/4681>\
**Category:** Ignition\
**Created:** [June 21, 2012, 1:19pm UTC](https://forum.inductiveautomation.com/t/tag-change-oldvalue/4681 "2012-06-21T13:19:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antonio](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@Antonio](https://forum.inductiveautomation.com/u/Antonio)\
**Post date:** [June 21, 2012, 1:19pm UTC](https://forum.inductiveautomation.com/t/tag-change-oldvalue/4681/1 "2012-06-21T13:19:15Z")

</div>

Hello I have a problem with the tag change event scritp.  
I have a opc tag that is giving me the controller state of one inverter in a solar plant.  
I need to register this states on the table of event. The problem is that the direfent states are given in one bit of the INT2, every bit on the word have a state. So i have made a script that check the value.

That working good, the problem is that with that when the int2 tag value change just in one bit, the rest of states are save in the event table too coz you can have more of one state in the same time. So in every single change in this tag, print this state and the rest of states that are still on. and making a lot of new rows in the event table that are repeat

[color=#008000]nuevo=newValue.value

if nuevo & (1 \<\< 0):  
accion=‘Deactivation from Radio Signal’  
target=‘Inverter 9 - LOCAL MVL9’  
system.db.runUpdateQuery(“INSERT INTO audit\_events (EVENT\_TIMESTAMP, ACTOR, ACTION, ACTION\_TARGET, ACTION\_VALUE, STATUS\_CODE,ORIGINATING\_SYSTEM, ORIGINATING\_CONTEXT) VALUES (NOW(),‘system info’,’%s’,’%s’,%d,0,‘project=solar\_plant’,2)” % (accion,target,nuevo))

if nuevo & (1 \<\< 1):  
accion=‘Deactivation caused by Overvoltage during limitation from power reduction’  
target=‘Inverter 9 - LOCAL MVL9’  
system.db.runUpdateQuery(“INSERT INTO audit\_events (EVENT\_TIMESTAMP, ACTOR, ACTION, ACTION\_TARGET, ACTION\_VALUE, STATUS\_CODE,ORIGINATING\_SYSTEM, ORIGINATING\_CONTEXT) VALUES (NOW(),‘system info’,’%s’,’%s’,%d,0,‘project=solar\_plant’,2)” % (accion,target,nuevo))  
.  
.  
.  
.[/color]

I would like to do something like that:

[color=#008000]nuevo=newValue.value  
viejo=oldValue.value

if nuevo & (1 \<\< 0) and not viejo & (1 \<\< 0):  
accion=‘Deactivation from Radio Signal’  
target=‘Inverter 9 - LOCAL MVL9’  
system.db.runUpdateQuery(“INSERT INTO audit\_events (EVENT\_TIMESTAMP, ACTOR, ACTION, ACTION\_TARGET, ACTION\_VALUE, STATUS\_CODE,ORIGINATING\_SYSTEM, ORIGINATING\_CONTEXT) VALUES (NOW(),‘system info’,’%s’,’%s’,%d,0,‘project=solar\_plant’,2)” % (accion,target,nuevo))

if nuevo & (1 \<\< 1) and not viejo & (1 \<\< 1):  
accion=‘Deactivation caused by Overvoltage during limitation from power reduction’  
target=‘Inverter 9 - LOCAL MVL9’  
system.db.runUpdateQuery(“INSERT INTO audit\_events (EVENT\_TIMESTAMP, ACTOR, ACTION, ACTION\_TARGET, ACTION\_VALUE, STATUS\_CODE,ORIGINATING\_SYSTEM, ORIGINATING\_CONTEXT) VALUES (NOW(),‘system info’,’%s’,’%s’,%d,0,‘project=solar\_plant’,2)” % (accion,target,nuevo))

if nuevo & (1 \<\< 2) and not viejo & (1 \<\< 2):  
accion=‘Voltage level to high for activation’  
target=‘Inverter 9 - LOCAL MVL9’  
system.db.runUpdateQuery(“INSERT INTO audit\_events (EVENT\_TIMESTAMP, ACTOR, ACTION, ACTION\_TARGET, ACTION\_VALUE, STATUS\_CODE,ORIGINATING\_SYSTEM, ORIGINATING\_CONTEXT) VALUES (NOW(),‘system info’,’%s’,’%s’,%d,0,‘project=solar\_plant’,2)” % (accion,target,nuevo))

if nuevo & (1 \<\< 3) and not viejo & (1 \<\< 3):  
accion=‘AC Power Limitation caused by over frequency’  
target=‘Inverter 9 - LOCAL MVL9’  
system.db.runUpdateQuery(“INSERT INTO audit\_events (EVENT\_TIMESTAMP, ACTOR, ACTION, ACTION\_TARGET, ACTION\_VALUE, STATUS\_CODE,ORIGINATING\_SYSTEM, ORIGINATING\_CONTEXT) VALUES (NOW(),‘system info’,’%s’,’%s’,%d,0,‘project=solar\_plant’,2)” % (accion,target,nuevo))  
.  
.  
.  
.  
[/color]

But i can not find the property that give me the old value.

PD: sorry for my english

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [June 21, 2012, 3:32pm UTC](https://forum.inductiveautomation.com/t/tag-change-oldvalue/4681/2 "2012-06-21T15:32:54Z")

</div>

Unfortunately, we don’t have the old value in tag change scripts. We only have the new one. You can always store the old value in the database or another memory tag.

---

<div class="post-metadata">

**Author:** ![Antonio](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@Antonio](https://forum.inductiveautomation.com/u/Antonio)\
**Post date:** [June 21, 2012, 5:39pm UTC](https://forum.inductiveautomation.com/t/tag-change-oldvalue/4681/3 "2012-06-21T17:39:46Z")

</div>

Yes i already used that

[color=#008000]nuevo=newValue.value  
viejo=int(system.db.runScalarQuery(“SELECT ACTION\_VALUE FROM audit\_events WHERE ACTION\_TARGET =‘Inverter 9 - LOCAL MVL9’ ORDER BY EVENT\_TIMESTAMP DESC LIMIT 1”))[/color]

But i think its nicer with one property oldValue. Anyway I would like to propose that for next generation of ignition your team programmer add one option to the tags for auto-create a event, not only Auditing.

Like when you configure the alarm to one tag but for auto made one event.  
Its a very powerfull tool for check the states of the systems, and right now i have to use every time the tag change event script that takes a lot of time.

Thanks a lot!
