In a project I inherited, we have this partcount INT tag configured with a COUNT query binding (SQL) populating the tag. I monitor that tag in the PLC to do other stuff.
Whenever the perspective session is opened, the tag briefly (half a sec) goes to zero and returns to it’s actual value. Tag group config looks like below:
So this is how the value is being written to the tag. The last line writes the value from a query binding to the tag. It’s run in a ValueChanged script
Is this change script on a numeric entry field? If it is, you might want to ignore all value changes except those originating from Browser, that should make sure it only fires when a user enters something.
For maintenance sake I would suggest the following improvements:
Make style classes for the different states of the header, and use a map transform to set the style class of the header based on the value of the property with this change script. Or just put an expression binding on the styles.backgroundColor property of the header, if you feel lazy.
The value driving this property change(or at least its source) should be in the view custom properties.
The header text should just be an expression binding.
Are you expecting it to only write/update tag values if the user has entered something? Or do you also want it to write/update if the value from the query changes?
This is not the place for this script then. This script will fire on every open perspective session running this project whenever the query result changes.
This is likely from the value changing from its uninitialized or default value to the value returned by the query, which will trigger the change script.
You may need to change your script to ignore the initial transition from default to actual.
Properties with bindings will either load with an uninitilized or default value on session startup and await their binding to return an actual value, and switch to that value once received. That transition will trigger a value changed script.