# Tag event write to file

**URL:** <https://forum.inductiveautomation.com/t/tag-event-write-to-file/21265>\
**Category:** Ignition\
**Created:** [December 6, 2018, 5:43pm UTC](https://forum.inductiveautomation.com/t/tag-event-write-to-file/21265 "2018-12-06T17:43:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsui](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@dsui](https://forum.inductiveautomation.com/u/dsui)\
**Post date:** [December 6, 2018, 5:43pm UTC](https://forum.inductiveautomation.com/t/tag-event-write-to-file/21265/1 "2018-12-06T17:43:30Z")

</div>

I am trying to implement a tag event script under the Value Changed event, where the tag value and timestamp are written to a .txt file whenever the value changes. I have the following code below under def valueChanged for a tag called tag1.

```
system.tag.write("[.]tag2", currentValue.value)
filename = "C:/Users/dsui/Documents/export.txt"
if filename != None:
	system.file.writeFile(filename, str(currentValue.value), 1)
	system.file.writeFile(filename, '\n', 1)
	system.file.writeFile(filename, str(currentValue.timestamp), 1)
	system.file.writeFile(filename, '\n', 1)

```

Whenever I change the of tag1 in the tag browser, I don’t see anything changes to the export.txt file. The script will successfully write the value of tag1 to tag2.

I also implemented the script below within the script console, and am able to write to the .txt file.

filename = “C:/Users/dsui/Documents/export.txt”  
if filename != None:  
tag1 = system.tag.read(‘Test/tag1’).value  
time = system.tag.read(‘Test/tag1’).timestamp  
system.file.writeFile(filename, str(tag1), 1)  
system.file.writeFile(filename, ‘\n’, 1)  
system.file.writeFile(filename, str(time), 1)  
system.file.writeFile(filename, ‘\n’, 1)

---

<div class="post-metadata">

**Author:** ![Stevenson.Yuan](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@Stevenson.Yuan](https://forum.inductiveautomation.com/u/Stevenson.Yuan)\
**Post date:** [December 6, 2018, 6:03pm UTC](https://forum.inductiveautomation.com/t/tag-event-write-to-file/21265/2 "2018-12-06T18:03:50Z")

</div>

TagEvents fire from the gateway scope- do you have the Ignition service running under a user account with access rights to the c:\users directory?

Try modifying the path to c:\temp\export.txt and if the tagevent is able to write to that location.

If you must write to protected directories you’ll need to give the service a user account:  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/2/2f2564fb4134e98b09a7cd18f4c6babc49ff2343.png)
