# Write and Read Tag

**URL:** <https://forum.inductiveautomation.com/t/write-and-read-tag/11085>\
**Category:** 3rd Party Modules\
**Created:** [January 21, 2016, 12:20pm UTC](https://forum.inductiveautomation.com/t/write-and-read-tag/11085 "2016-01-21T12:20:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cochi](https://avatars.discourse-cdn.com/v4/letter/c/ea666f/32.png) [@Cochi](https://forum.inductiveautomation.com/u/Cochi)\
**Post date:** [January 21, 2016, 12:20pm UTC](https://forum.inductiveautomation.com/t/write-and-read-tag/11085/1 "2016-01-21T12:20:07Z")

</div>

Is there a way of write and read Tags values with the SDK Module?  
I want to add Scripting functions and, in one of the methods, I need to read and write Tags values.  
It would be like using the method: system.tag.write(“TAG/value”,5), but with the SDK Module…

---

<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:** [January 21, 2016, 1:32pm UTC](https://forum.inductiveautomation.com/t/write-and-read-tag/11085/2 "2016-01-21T13:32:45Z")

</div>

In your module hook, save the context. Then you can use context.getTagManager() to obtain the root of the SQLtags tree. Use the TagPathParser.parse() function to convert tag path strings into tag path objects, which can then be used to obtain a tag node from the tag manager. And then you can read and write using the tag node object.

---

<div class="post-metadata">

**Author:** ![Cochi](https://avatars.discourse-cdn.com/v4/letter/c/ea666f/32.png) [@Cochi](https://forum.inductiveautomation.com/u/Cochi)\
**Post date:** [January 21, 2016, 2:32pm UTC](https://forum.inductiveautomation.com/t/write-and-read-tag/11085/3 "2016-01-21T14:32:50Z")

</div>

Ok, I wrote the following code:  
ContextManager context=ContextManager.getInstance();  
SQLTagsManager tagManager=context.getContext().getTagManager();  
TagPath tagPath = null;  
try {  
tagPath=TagPathParser.parse(path);  
} catch (IOException ex) {  
Logger.getLogger(Utilitario.class.getName()).log(Level.SEVERE, null, ex);  
}  
Tag tag=tagManager.getTag(tagPath);  
tag.getValue().getValue();

But the Tag object has no method setValue  
What I’m doing wrong?

---

<div class="post-metadata">

**Author:** ![mgross](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mgross/32/3311_2.png) [@mgross](https://forum.inductiveautomation.com/u/mgross)\
**Post date:** [January 21, 2016, 2:51pm UTC](https://forum.inductiveautomation.com/t/write-and-read-tag/11085/4 "2016-01-21T14:51:56Z")

</div>

Try adding this:

```auto
List<WriteRequest<TagPath>> writes = new ArrayList<WriteRequest<TagPath>>(1);
writes.add(new BasicWriteRequest<TagPath>(tagPath, value));
tagManager.write(writes, null, true);
```
