# Unchanged values being stored using trigger "Only evaluate when values have changed"

**URL:** <https://forum.inductiveautomation.com/t/unchanged-values-being-stored-using-trigger-only-evaluate-when-values-have-changed/67890>\
**Category:** Ignition\
**Created:** [December 21, 2022, 6:26pm UTC](https://forum.inductiveautomation.com/t/unchanged-values-being-stored-using-trigger-only-evaluate-when-values-have-changed/67890 "2022-12-21T18:26:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bill\_Sikorski](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Bill\_Sikorski](https://forum.inductiveautomation.com/u/Bill_Sikorski)\
**Post date:** [December 21, 2022, 6:26pm UTC](https://forum.inductiveautomation.com/t/unchanged-values-being-stored-using-trigger-only-evaluate-when-values-have-changed/67890/1 "2022-12-21T18:26:31Z")

</div>

I am trying to monitor my PLC for setpoint changes which don't occur very often.  
I am using the "Only evaluate when values have changed" without a "Trigger on Item".  
I have about 30 setpoints so this feature works well without having to write PLC code.  
The trigger always works when the values change.

Issue:  
My issue is sometimes it inserts a record even though the values haven't changed. This seems like maybe it is somekind of OPC disconnect but I'm not really sure. I get a few random inserts happening at night when the machine is idle but no one is at the machine. I end up with essentially duplicate records (even though no changes occur) every morning when I check.

Solution:  
Not sure what to do to eliminate this (or if its possible). I was thinking about writing code in SQL db to delete these duplicate values via Rollback. Any body else come across this and have any good solutions?

Thanks

---

<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 21, 2022, 6:33pm UTC](https://forum.inductiveautomation.com/t/unchanged-values-being-stored-using-trigger-only-evaluate-when-values-have-changed/67890/2 "2022-12-21T18:33:29Z")

</div>

I tend to use scripted inserts instead of transaction groups when triggering is anything other than the simplest value change, or a reliable handshake is required, or complex duplicate detection is required (which generally requires a custom DB query during startup to cache the true last recorded value).

Scripting is a _ **good** _ solution, but not necessarily _ **easy** _.

---

<div class="post-metadata">

**Author:** ![Bill\_Sikorski](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Bill\_Sikorski](https://forum.inductiveautomation.com/u/Bill_Sikorski)\
**Post date:** [December 21, 2022, 9:24pm UTC](https://forum.inductiveautomation.com/t/unchanged-values-being-stored-using-trigger-only-evaluate-when-values-have-changed/67890/3 "2022-12-21T21:24:55Z")

</div>

Hi. Can you expand on what you mean by "when triggering is anything other than the simplest value change".  
My group seems straightforward though there are several values (30 numeric mostly integer values) not just 1 or 2.  
I would like to understand what is making Ignition think there is a change in the values (when there isn't).  
Thanks,

---

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [May 24, 2023, 2:11pm UTC](https://forum.inductiveautomation.com/t/unchanged-values-being-stored-using-trigger-only-evaluate-when-values-have-changed/67890/4 "2023-05-24T14:11:18Z")

</div>

> [@Bill\_Sikorski](#):
>
> understand wh

Just came across this while searching for something. I know this older question.

What I did for something very similar is on my tag  
Tag Change Script

If new Value \<\> old value  
Then SQL insert command  
Execute SQL

Since it is on tag change script it gets triggered when value changes but it checks to see if value actually changes (I believe the tag change script does trigger sometimes due to quality change thus the check to see if new value and old value are different.) This should solve your issue of non change entries.

Here is the code I am using  
Had some issues if the value was blank so I check for that and insert "Null" for value  
Verify the value did change  
Update new value into DB table  
Insert row into audit table to see when it was changed + values.

```auto
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):

	
		DB = "DatabaseName"
		ColChange = tag.TagName
		OldValue = previousValue.value
		if (OldValue == None):
			OldValue = "NULL" 
		NewValue = currentValue.value
		if (NewValue == None):
			NewValue = "NULL"
		if NewValue <> OldValue:
			paths="[.]UniqueID"
			values=system.tag.readBlocking(paths)
			args= NewValue ,values[0].value
			query = "UPDATE Input SET " + ColChange + " = ? OUTPUT INSERTED.UniqueID WHERE UniqueID = ?"
			Update = system.db.runPrepQuery(query,args, DB)
			UpdateID = Update.getValueAt(0,0)
			auditQuery = "INSERT INTO InputAuditLog (ModifiedID, OldValue, NewValue, ColumnChanged, TagPath) VALUES (?,?,?,?,?)"
			auditArgs = UpdateID, OldValue, NewValue, ColChange, tagPath
			system.db.runPrepUpdate(auditQuery, auditArgs, DB)

```
