Tag change script executes on restart of tag

We have found this thing that where a restart of a tag triggers tag-change script. This feels pretty normal since the tag is restarted. In the script we check for initial condition but the script runs anyway.
The tag change trigger only looks at value. The value is not changed.

Is there any other flag to look at when doing a tag restart?
Is this a bug?

We run 8.1.6.


When a tag restarts it is very briefly Null. So there really is a value change when the first OPC value arrives. At least, that’s what it looks like to me. Not really a bug, just an implementation detail.

Ok. Do you now any good way to handle this behaviour?

You can condition your script like this

if not initialChange and previousValue.value is not None and currentValue.value is not None:


1 Like

Thanks, I try this.

We ended upp with a condition looking like this

if not initialChange and event.getPreviousValue().getValue() is not None and newValue.getValue() is not None:

You should note that if the value really does change while the tag is restarting, this approach will ignore it. If running extra is more of a problem than a rare miss, then carry on. The bottom line is that the tag itself doesn’t have enough information (cannot) to perfectly delivery value changes through a restart.

You need something that isn’t affected by the tag restart to hold state of some kind. For the simplest case, I recommend using a memory tag to hold the previous value. Then do not check initialChange. Just always check the delivered new value against the memory tag. If they are different, write the new value to the memory tag and proceed with the rest of the logic.

If the script is supposed to do database operations or other external operations, a more robust solution would be to cache the last successful operation in a project script top level variable. When accessed the first time after a script restart (cache==None), read from the DB or external server to populate the cache.