# Tag valueChanged event execution

**URL:** <https://forum.inductiveautomation.com/t/tag-valuechanged-event-execution/11784>\
**Category:** Ignition\
**Created:** [June 7, 2016, 8:10am UTC](https://forum.inductiveautomation.com/t/tag-valuechanged-event-execution/11784 "2016-06-07T08:10:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [June 7, 2016, 8:10am UTC](https://forum.inductiveautomation.com/t/tag-valuechanged-event-execution/11784/1 "2016-06-07T08:10:30Z")

</div>

Hi,  
I'm using the tag valueChanged event to implement a process log: the process tag is a boolean variable read from an AB CompactLogix plc through an Ignition device.  
My logic should be as follows: each time I see an OFF-\>ON transition of the variable, I add a process record in a table of an SQL Server database with its start datetime - let's say process X has been added; each time I see an ON-\>OFF transition, I "close" process X, by updating its end time.  
The python script in the valueChanged event is:

`if not initialChange and currentValue.quality.isGood():
	if currentValue.value:
		#add a new process record in the database
	else:
		#update process end datetime`  
What it's weird is that whenever I restart the PC or shutdown/startup Ignition service or disconnect/connect the PLC, if the process boolean variable is true when the system comes on again, a new process record gets added: that is not right, because the process variable was already true and Ignition did not catch any transition in my opinion. I thought that if not initialChange condition was the solution, but it isn't.

Any suggestion? Is anyone exactly aware of when the valueChanged event is called on a variable? The event comment says

> [@](#):
>
> Fired whenever the current value changes in value or quality

But I'm not quite sure

Thanks in advance, regards

---

<div class="post-metadata">

**Author:** ![andrea.minu](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/andrea.minu/32/3326_2.png) [@andrea.minu](https://forum.inductiveautomation.com/u/andrea.minu)\
**Post date:** [June 7, 2016, 9:11am UTC](https://forum.inductiveautomation.com/t/tag-valuechanged-event-execution/11784/2 "2016-06-07T09:11:55Z")

</div>

Hi pgmo,

You should check also the previous quality of the tag value ,so the script could be:

`
if not initialChange and currentValue.quality.isGood() and previuosValue.quality.isGood():
   if currentValue.value:
      #add a new process record in the database
   else:
      #update process end datetime`

Best,

Andrea

---

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [June 7, 2016, 9:29am UTC](https://forum.inductiveautomation.com/t/tag-valuechanged-event-execution/11784/3 "2016-06-07T09:29:35Z")

</div>

I’ll give it a try,

thanks, regards
