# Writing tag values

**URL:** <https://forum.inductiveautomation.com/t/writing-tag-values/9191>\
**Category:** Module Development\
**Created:** [October 17, 2014, 4:44pm UTC](https://forum.inductiveautomation.com/t/writing-tag-values/9191 "2014-10-17T16:44:13Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [October 17, 2014, 4:44pm UTC](https://forum.inductiveautomation.com/t/writing-tag-values/9191/1 "2014-10-17T16:44:13Z")

</div>

Hi,

I am trying to write values (from my gateway module) in tags using the following write method of SQLTagsManager interface:

java.util.List write(java.util.List\<WriteRequest\> writes, AuthenticatedUser user, boolean isSystem)  
Writes to the tags/properties defined by the tag paths.

But i am at a loss how initialize the AuthenticatedUser user implementing class? Can someone please guide me with an exapmle.

regards  
PRAMANJ  
😢

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 20, 2014, 4:51pm UTC](https://forum.inductiveautomation.com/t/writing-tag-values/9191/2 "2014-10-20T16:51:49Z")

</div>

If you’re calling this from a gateway module without being invoked in a context where you might have an AuthenticatedUser object (an RPC call from the client for example) then you can use a null value for user and the isSystem flag to true.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [October 21, 2014, 4:24am UTC](https://forum.inductiveautomation.com/t/writing-tag-values/9191/3 "2014-10-21T04:24:34Z")

</div>

Hi Kevin,  
Thanks for your reply. I tried writing using following code

```
			    WriteQuality = SQLTagManagerContext.write(writepaths, new BasicAuthenticatedUser(null, null ) , true );

```

where writepaths is declared as a local variable as follows:  
  
List\<WriteRequest\> writepaths = new ArrayList \<WriteRequest\> ();

and WriteQuality is declared as local variable as follows:  
  
java.util.List WriteQuality = new ArrayList ();

I get a run time exception at the "write" method execution, whereas the compilation and goes thru and build is successful!

Would appreciate your early reply,  
Best regards  
PRAMANJ

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 21, 2014, 3:16pm UTC](https://forum.inductiveautomation.com/t/writing-tag-values/9191/4 "2014-10-21T15:16:41Z")

</div>

Use a null value for the user:

```auto
WriteQuality = SQLTagManagerContext.write(writepaths, null, true);
```

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [October 21, 2014, 4:38pm UTC](https://forum.inductiveautomation.com/t/writing-tag-values/9191/5 "2014-10-21T16:38:08Z")

</div>

Hi Kevin,  
Thanks for the reply. The execution goes through now but I don't get the right results!  
Is my initialization of writepaths correct in the following code?

List\<WriteRequest\> writepaths = new ArrayList \<WriteRequest\> ();  
writepaths.add(new BasicAsyncWriteRequest(TagPathParser.parse(...the path string...),Integer.parseInt("5"));  
java.util.List WriteQuality = new ArrayList ();  
WriteQuality = SQLTagManagerContext.write(writepaths, null, true);  
out.println(WriteQuality.get(0).isGood());  
writepaths.clear();

The isGood() returns false and value of the tag given in the tagpath string remains null!

What am i doing wrong!  
regards  
PRAMANJ

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 21, 2014, 5:48pm UTC](https://forum.inductiveautomation.com/t/writing-tag-values/9191/6 "2014-10-21T17:48:22Z")

</div>

Try printing the name and description from the Quality you get and see if there’s any hints.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [October 21, 2014, 6:00pm UTC](https://forum.inductiveautomation.com/t/writing-tag-values/9191/7 "2014-10-21T18:00:37Z")

</div>

when i print the two value it gives "Access Denied ACCESS\_DENIED" for name and description respectively. I am trying to write to one of the tags of the simpleTagProvider example given in your SDK extended to 20 tags from 10 tags given in the example.  
PRAMANJ

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [October 21, 2014, 6:04pm UTC](https://forum.inductiveautomation.com/t/writing-tag-values/9191/8 "2014-10-21T18:04:01Z")

</div>

sorry values "Access Denied ACCESS\_DENIED" are for description and name respectively, not name and description respectively.  
regards  
PRAMANJ

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 21, 2014, 6:21pm UTC](https://forum.inductiveautomation.com/t/writing-tag-values/9191/9 "2014-10-21T18:21:44Z")

</div>

Did you register a WriteHandler on the SimpleTagProvider?

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [October 21, 2014, 6:34pm UTC](https://forum.inductiveautomation.com/t/writing-tag-values/9191/10 "2014-10-21T18:34:21Z")

</div>

The SimpleTagProvider example already has the following code:

ourProvider.registerWriteHandler(CONTROL\_TAG, new WriteHandler() {  
 @Override  
public Quality write(TagPath target, Object value) {  
Integer intVal = TypeUtilities.toInteger(value);  
//The adjustTags function will add/remove tags, AND update the current value of the control tag.  
adjustTags(intVal);  
return CommonQualities.GOOD;  
}  
});

But I am not using this write method! I am just using the following call as explained in my earlier reply.

WriteQuality = SQLTagManagerContext.write(writepaths, null, true);

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 21, 2014, 6:37pm UTC](https://forum.inductiveautomation.com/t/writing-tag-values/9191/11 "2014-10-21T18:37:50Z")

</div>

If you’re writing to a TagPath that you haven’t registered a WriteHandler for in the SimpleTagProvider then you’ll get the Access Denied quality…

try writing to whatever the TagPath for that CONTROL\_TAG that has a registered handler is and see if it works.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [October 21, 2014, 6:42pm UTC](https://forum.inductiveautomation.com/t/writing-tag-values/9191/12 "2014-10-21T18:42:17Z")

</div>

Thanks lot kevin. I will try it tomorrow as its already midnight here.  
Best regards  
PRAMANJ

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [October 22, 2014, 5:41am UTC](https://forum.inductiveautomation.com/t/writing-tag-values/9191/13 "2014-10-22T05:41:49Z")

</div>

That means only the registered tag provider can update value of any of its own tags not some someone else? What if I want to update one of the SimpleTageProvider's tags given in the examples in SDK from my gatewayHook Module using the write method of SQLTagsManager interface. I thought the isSystem flag set to true will override access qualifier for tags for a gateway module! Is there any way I can write a value on any tag in the system from my gateway module? How does ignition client write to a PLC input tag from an input button on client, to switch ON/OFF an equipment?  
regards  
PRAMANJ

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 22, 2014, 1:47pm UTC](https://forum.inductiveautomation.com/t/writing-tag-values/9191/14 "2014-10-22T13:47:12Z")

</div>

The TagProvider a tag belongs to is ultimately responsible for allowing the tag to be written or not.

With the SimpleTagProvider the very first thing required for allowing writes is having a WriteHandler for that tag. If you control the SimpleTagProvider AND you want to write to a tag, then you’ll need a WriteHandler.

If you’re writing to tags belonging to another tag provider you’re at the mercy of the provider to allow you to write. While the SimpleTagProvider requires WriteHandlers be registered for any tag to write, other tag providers are all free to work in their own way.

In your test code if you were writing an OPC or memory tag belonging to the internal provider instead of a SimpleTagProvider that you aren’t registering WriteHandlers on your write would likely go through, assuming you had the correct TagPath and permissions (or use system flag + null user).

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [October 22, 2014, 3:41pm UTC](https://forum.inductiveautomation.com/t/writing-tag-values/9191/15 "2014-10-22T15:41:37Z")

</div>

Hi Kevin,  
That makes sense! Bottom line is it should be tag driven by Internal tag provider and memory tag or even OPC tag. (bit surprised about OPC tag is also writable! Perhaps it may also have some access protection in the address space it belongs to).

I think reading any valid tag path doesn't have any such restriction about internal or external tag provider or memory or database tag etc. Please correct me if I am wrong.

Best regards  
PRAMANJ
