# Trouble getting Value Changed event to fire

**URL:** <https://forum.inductiveautomation.com/t/trouble-getting-value-changed-event-to-fire/43852>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [February 25, 2021, 10:22pm UTC](https://forum.inductiveautomation.com/t/trouble-getting-value-changed-event-to-fire/43852 "2021-02-25T22:22:07Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![israel.jordan](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@israel.jordan](https://forum.inductiveautomation.com/u/israel.jordan)\
**Post date:** [February 25, 2021, 10:22pm UTC](https://forum.inductiveautomation.com/t/trouble-getting-value-changed-event-to-fire/43852/1 "2021-02-25T22:22:07Z")

</div>

Hi all,

I have a tag that has some other tags inside of it. On one of the inner tags, I have a Value Changed event script that I am expecting to fire whenever the tags value is modified. In order to test, I have created a shared script that writes to the tag in question. After running the script, I can see that the tags value has changed but I am unable to get my script to fire. I have placed a print statement at the start of the script but I have yet to see output. Can someone please point me in the right direction?

Thanks in advance,

Israel

---

<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:** [February 26, 2021, 12:42am UTC](https://forum.inductiveautomation.com/t/trouble-getting-value-changed-event-to-fire/43852/2 "2021-02-26T00:42:11Z")

</div>

Is the shared script containing the called function in your [Gateway Scripting Project](https://docs.inductiveautomation.com/display/DOC81/Gateway+Settings)?

---

<div class="post-metadata">

**Author:** ![israel.jordan](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@israel.jordan](https://forum.inductiveautomation.com/u/israel.jordan)\
**Post date:** [February 26, 2021, 3:18pm UTC](https://forum.inductiveautomation.com/t/trouble-getting-value-changed-event-to-fire/43852/3 "2021-02-26T15:18:47Z")

</div>

Yes, it is. I call it using the Script Console. I have placed print statements inside of it also. I can see the output. I can see that the tag value has changed. But the event script does not fire after the writing to the tag. When this goes to production the tag type will be changed to an OPC tag. In the meantime, I have temporarily changed it to a Memory tag for testing purposes. I am using Ignition 8.0 and `system.tag.writeAsync()` to write to the tag. I am not sure if this helps or not but after writing to the tag, I tried to read from it using `system.tag.readAsync()`. When I print the results, they print as “None”.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 26, 2021, 3:49pm UTC](https://forum.inductiveautomation.com/t/trouble-getting-value-changed-event-to-fire/43852/4 "2021-02-26T15:49:49Z")

</div>

> [@israel.jordan](#):
>
> `system.tag.writeAsync()` to write to the tag. I am not sure if this helps or not but after writing to the tag, I tried to read from it using `system.tag.readAsync()`

This will likely not give you the results you want, `system.tag.writeAsync()` merely sets the write in process then moves on to the next line. So when you call `system.tag.readAsync()` you are not guaranteed that the write has occured.

Can you share your script? Even a redacted version would help us help you.

---

<div class="post-metadata">

**Author:** ![israel.jordan](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@israel.jordan](https://forum.inductiveautomation.com/u/israel.jordan)\
**Post date:** [February 26, 2021, 4:09pm UTC](https://forum.inductiveautomation.com/t/trouble-getting-value-changed-event-to-fire/43852/5 "2021-02-26T16:09:24Z")

</div>

Yes, code below.

```auto
def send_data():
	
	print "Inside of send_tcp trying to send"
	
	data = "<TESTDATA><DATETIME> 2014-12-20 4:42:30 </DATETIME></TESTDATA>\r\n"
	print "Sending this data: " + data
	
	newTime = system.date.now()
	print "this is the new time -> " + str(newTime)
	system.tag.writeAsync(["[default]Folder1/Folder2/Outer_Tag/InnerTag1"], [newTime])
	system.tag.writeAsync(["[default]Folder1/Folder2/Outer_Tag/InnerTag2"], [data])
	
	writtenData = system.tag.readAsync(["[default]Folder1/Folder2/Outer_Tag/InnerTag1"])
	writtenDate = system.tag.readAsync(["[default]Folder1/Folder2/Outer_Tag/InnerTag2"])
	
	print ".........The ValueChanged should have fired off by now........."
	
	print "This data has been read from the InnerTag1 tag"
	print writtenData
	print "This date has been read from the InnerTag2 tag"
	print writtenDate 
	print "done"

```

---

<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:** [February 26, 2021, 4:13pm UTC](https://forum.inductiveautomation.com/t/trouble-getting-value-changed-event-to-fire/43852/6 "2021-02-26T16:13:59Z")

</div>

The .readAsync() function doesn’t return tag data. You need to use readBlocking() for that. (And it would be a list of QVs, not a single value.) And since you are writing asynchronously above that, you are unlikely to have the writes finished by the time you read. You might want to spend some time with the user manual pages for these scripting functions. ):

---

<div class="post-metadata">

**Author:** ![israel.jordan](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@israel.jordan](https://forum.inductiveautomation.com/u/israel.jordan)\
**Post date:** [February 26, 2021, 4:16pm UTC](https://forum.inductiveautomation.com/t/trouble-getting-value-changed-event-to-fire/43852/7 "2021-02-26T16:16:45Z")

</div>

Okay thank you, I will do that. Can you please tell me if I should expect the Value Changed event to fire when I write to the tag using script?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 26, 2021, 4:26pm UTC](https://forum.inductiveautomation.com/t/trouble-getting-value-changed-event-to-fire/43852/8 "2021-02-26T16:26:33Z")

</div>

Don't do this:

```auto
system.tag.writeAsync(["[default]Folder1/Folder2/Outer_Tag/InnerTag1"], [newTime])
system.tag.writeAsync(["[default]Folder1/Folder2/Outer_Tag/InnerTag2"], [data])

```

Do this instead:

```auto
system.tag.writeAsync(['[default]Folder1/Folder2/Outer_Tag/InnerTag1','[default]Folder1/Folder2/Outer_Tag/InnerTag2'],[newTime,data])

```

Same goes for reading tags as well.

Oh also, as @pturmel pointed out, taking a look at the manual entries for these functions would probably be beneficial

[https://docs.inductiveautomation.com/display/DOC81/system.tag.writeAsync](https://docs.inductiveautomation.com/display/DOC81/system.tag.writeAsync)

> [@israel.jordan](#):
>
> Can you please tell me if I should expect the Value Changed event to fire when I write to the tag using script?

Yes, the ValueChanged tag event should fire from any change, weather that change is manual entry in the designer, a script, or an OPC Read.

---

<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:** [February 26, 2021, 4:29pm UTC](https://forum.inductiveautomation.com/t/trouble-getting-value-changed-event-to-fire/43852/9 "2021-02-26T16:29:51Z")

</div>

Consider testing your valueChange script by just using the tag editor to set different values. Later, work on your script to write to the tag.

---

<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:** [February 26, 2021, 4:32pm UTC](https://forum.inductiveautomation.com/t/trouble-getting-value-changed-event-to-fire/43852/10 "2021-02-26T16:32:14Z")

</div>

Also, keep in mind that tag events (and most any others) run in their own threads in the gateway, from a queued thread pool. Even when using writeBlocking, you can’t be sure that a following read will happen _after_ the corresponding tag change script.
