So, I am struggling with a Tag Event (Value Change) script on a Memory Document tag. (Gateway V8.1.0)
Ideally, I want the user to click a button on a perspective view that writes to a custom prop (type:object) that in turn is bidirectionally bound to the Document tag.
In an effort to troubleshoot, I have removed all scripting and have simply written the following into the Value Changed script on the tag:
Now, if I manually change one of the values in the Document tag via Tag Browser, (click Commit -> Apply) then the Value Changed script fires. If, however, I write to this Document tag via the Perspective object binding or even using system.tag.writeBlocking() from script console, the Value Changed event does not seem to fire. The actual value of the tag changes, based on animations I have in Perspective views as well as by confirming via Tag Browser, but the script does not fire on the gateway.
There is no gateway log entry to point to any script fault (and there shouldnât be any, since it runs fine when modifying the Document tag via Tag Browser).
I feel like Iâm doing something silly because I havenât found any similar forum posts with this issue. Has anyone else experienced this?
Yep, it does, but thought I would check here first in case itâs something obvious or has already been logged as a bug.
So, some more info:
I created a new tag on a separate project to see if I can get to the bottom of it, and it seems like if I write to the entire Document value, then it registers as a Value Change. If I write to a nested member of the JSON (forgive my terminology if not quite accurate) value then it does not trigger.
So, in the example below, a change to [âstrTextâ] triggers the Value Change script on the tag, but a change to [âL2â][âstrTextâ] does not:
Again, if I write to this nested member via Tag Browser, then it does trigger the Value Change script presumably because applying a change via Tag Browser initiates some kind of ârefreshâ.
Well, with that detail, it isnât a bug (in Ignition). For tags containing objects (datasets, strings, documents), the contents are not supposed to be edited in place. Replacing the object with an updated version is the definition of a âchangeâ. Yes, as youâve seen, reads of the tag will deliver the content of something updated in place, but bindings or change events wonât be triggered.
It may not be the most elegant, but I have unticked bidirectional binding in Perspective now and added a datachange script onto the custom prop to write the entire object (after a little dict to JSON dance) back to the tag and that seems to work.
Thank you very much for your insight, @pturmel! Enjoy the rest of your Sunday