# Tag Event Script on Document tag

**URL:** <https://forum.inductiveautomation.com/t/tag-event-script-on-document-tag/40673>\
**Category:** Ignition\
**Created:** [November 15, 2020, 3:27pm UTC](https://forum.inductiveautomation.com/t/tag-event-script-on-document-tag/40673 "2020-11-15T15:27:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhiren.naidoo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dhiren.naidoo/32/19485_2.png) [@dhiren.naidoo](https://forum.inductiveautomation.com/u/dhiren.naidoo)\
**Post date:** [November 15, 2020, 3:27pm UTC](https://forum.inductiveautomation.com/t/tag-event-script-on-document-tag/40673/1 "2020-11-15T15:27:04Z")

</div>

Hi everyone

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:

```auto
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
    logger = system.util.getLogger('TagChange_')
    logger.info('TagChange triggered')

```

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?

---

<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:** [November 15, 2020, 5:03pm UTC](https://forum.inductiveautomation.com/t/tag-event-script-on-document-tag/40673/2 "2020-11-15T17:03:06Z")

</div>

Sounds like a bug worth reporting to support.

---

<div class="post-metadata">

**Author:** ![dhiren.naidoo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dhiren.naidoo/32/19485_2.png) [@dhiren.naidoo](https://forum.inductiveautomation.com/u/dhiren.naidoo)\
**Post date:** [November 15, 2020, 7:47pm UTC](https://forum.inductiveautomation.com/t/tag-event-script-on-document-tag/40673/3 "2020-11-15T19:47:29Z")

</div>

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:  
 ![Capture_IGN](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/f/ff76c25d860e1e682abd001f2232494c7a608ebd.png)

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”.

Does look like I will need to contact support…

---

<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:** [November 15, 2020, 7:57pm UTC](https://forum.inductiveautomation.com/t/tag-event-script-on-document-tag/40673/4 "2020-11-15T19:57:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dhiren.naidoo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dhiren.naidoo/32/19485_2.png) [@dhiren.naidoo](https://forum.inductiveautomation.com/u/dhiren.naidoo)\
**Post date:** [November 15, 2020, 8:05pm UTC](https://forum.inductiveautomation.com/t/tag-event-script-on-document-tag/40673/5 "2020-11-15T20:05:31Z")

</div>

I see! Did not realise that…

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 🙂
