# How to trigger script on timestamp change

**URL:** <https://forum.inductiveautomation.com/t/how-to-trigger-script-on-timestamp-change/57361>\
**Category:** Ignition\
**Created:** [March 18, 2022, 1:47pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-on-timestamp-change/57361 "2022-03-18T13:47:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alistair\_Trout](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@Alistair\_Trout](https://forum.inductiveautomation.com/u/Alistair_Trout)\
**Post date:** [March 18, 2022, 1:47pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-on-timestamp-change/57361/1 "2022-03-18T13:47:28Z")

</div>

Hi Guys,

So I’m trying to make a counter for a system I’m helping build - we’ve got 1D/2D scanners that take an image of a QR code, the scanner then sends this value to a tag on ignition as a string. Unfortunately the inbuilt statistics for the scanners are poor and would like to build my own counter to monitor the success / fail rate of them.

The tag that receives the string from the scanner filters through the string and pulls a ‘Box ID’ out used to identify individual boxes. I then write this Box ID string to another tag with another valueChanged script. We convert a ‘FailedRead’ value from the scanner to a 0 and increment our fail counter and use an else statement to increment our success counter (we assume anything other than a 0 was a pass).

However the issue I’m facing is that when I increment my fail counter - it will only take affect the first time. In order to get a second increment a pass has to occur before. I know this is because I’m just writing a 0 back to the tag for a second time if a fail occurs again.

My question is - how can I have a script trigger based on a timestamp change rather than a value change? I don’t want to start giving the tag more than 1 value for a failed read but obviously writing the same value back to the tag won’t trigger the value changed script.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 18, 2022, 3:11pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-on-timestamp-change/57361/2 "2022-03-18T15:11:14Z")

</div>

You could possibly try the following:

- Create a _ScannerTimestamp_ expression tag, set the _Data Type_ to `DateTime` and set the expression to `{[~]Scanner.Timestamp}`, where _Scanner_ is your scanner string tag.
- Now you should be able to trigger the script on ScannerTimestamp’s _Value Changed_ event.

I don’t have a scanner with which to test this.

---

<div class="post-metadata">

**Author:** ![Alistair\_Trout](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@Alistair\_Trout](https://forum.inductiveautomation.com/u/Alistair_Trout)\
**Post date:** [March 18, 2022, 7:55pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-on-timestamp-change/57361/3 "2022-03-18T19:55:11Z")

</div>

Tried the suggestion - same problem though. If I set the scanner tag to null and write a 0 from a separate tag it updates the timestamp on the first write, subsequent writes however have no change on the timestamp.

---

<div class="post-metadata">

**Author:** ![Alistair\_Trout](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@Alistair\_Trout](https://forum.inductiveautomation.com/u/Alistair_Trout)\
**Post date:** [March 18, 2022, 8:05pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-on-timestamp-change/57361/4 "2022-03-18T20:05:56Z")

</div>

Tried the suggestion - same problem though. If I set the scanner tag to null and write a 0 from a separate tag it updates the timestamp on the first write, subsequent writes however have no change on the timestamp.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 18, 2022, 10:24pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-on-timestamp-change/57361/5 "2022-03-18T22:24:42Z")

</div>

Timestamps generally don’t change unless the value changes.

There is perhaps one exception to this, with OPC tags from an OPC UA server where you’ve enabled the “Include Timestamp-Only Changes” setting on that tag group, but even then it’s only some servers that will send timestamp-only changes.

As far as the rest of the Ignition tag system works change events only trigger on value change.

When you write 0 to a tag with a null value that’s a change, but if you keep trying to write 0 to it nothing is actually happening.

---

<div class="post-metadata">

**Author:** ![Alistair\_Trout](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@Alistair\_Trout](https://forum.inductiveautomation.com/u/Alistair_Trout)\
**Post date:** [March 18, 2022, 11:41pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-on-timestamp-change/57361/6 "2022-03-18T23:41:46Z")

</div>

I know so thats my problem - the scanner gives me a string of ‘FailedRead’ when it doesn’t scan the QR code. I convert that to a 0 for a counter I use pass/fail/total. I can’t think of a better way to count up the data.

I was trying to fire the counter logic when the FailedRead occurred - receive ‘FailedRead’ convert to 0 on a separate integer memory tag, if not 0 then the box ID which I get from the QR so we count that as a pass and do the counter logic.

Is there an easier way of triggering the counter.

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [March 19, 2022, 12:12am UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-on-timestamp-change/57361/7 "2022-03-19T00:12:54Z")

</div>

If i am understanding your question, the problem is that back to back fail reads don’t count twice. it sounds like you have a solution, but i don’t really get what it is.

You could write the result of your scan to a tag and then have a tag change script that “clears” the tag out when a change occurs. In your counter logic you would not increment either the pass or fail totals when a clear happens.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 19, 2022, 9:12am UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-on-timestamp-change/57361/8 "2022-03-19T09:12:51Z")

</div>

> [@Alistair\_Trout](#):
>
> I know this is because I’m just writing a 0 back to the tag for a second time if a fail occurs again.

If you're the one writing the 0, then it means that you detected a change. Why not increment the counter at this time instead of going through an indirection that doesn't seem to work ?  
I think I'm missing something about your issue, could you be more descriptive about what you want and what you're doing ?
