# How to check if user has right to write a variable from button event script

**URL:** <https://forum.inductiveautomation.com/t/how-to-check-if-user-has-right-to-write-a-variable-from-button-event-script/94243>\
**Category:** Ignition\
**Tags:** scripting, perspective\
**Created:** [August 6, 2024, 5:49pm UTC](https://forum.inductiveautomation.com/t/how-to-check-if-user-has-right-to-write-a-variable-from-button-event-script/94243 "2024-08-06T17:49:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olivier\_Canuel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/olivier_canuel/32/66088_2.png) [@Olivier\_Canuel](https://forum.inductiveautomation.com/u/Olivier_Canuel)\
**Post date:** [August 6, 2024, 5:49pm UTC](https://forum.inductiveautomation.com/t/how-to-check-if-user-has-right-to-write-a-variable-from-button-event-script/94243/1 "2024-08-06T17:49:25Z")

</div>

Hello,

I have an application where security is managed through tags. The tags have different security levels depending on who can write to them.

My problem is that I have buttons that write to these tags via system.tag.writeAsync. The security levels work, but there is no confirmation when nothing happens because the user doesn't have the correct security level.

I could manually assign security levels to the scripts, but that would be duplicating work (tag + event script). Additionally, I would like to only change one place if we want to add user categories that can change a tag, rather than changing all the different places where this tag is written.

Is it possible in event scripts to easily detect if the user can write to a tag?

Thank you and have a great day!

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [August 6, 2024, 7:39pm UTC](https://forum.inductiveautomation.com/t/how-to-check-if-user-has-right-to-write-a-variable-from-button-event-script/94243/2 "2024-08-06T19:39:43Z")

</div>

Have you checked the results you get from the writeAsync via the callback function? Via the documentation - [system.tag.writeAsync | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-writeAsync)

```python
paths = ["[default]Tag1", "[default]Folder/Tag2"]
values = [10, 10]
 
def myCallback(asyncReturn):
    for result in asyncReturn:
        # Do something if a bad qualified value was returned
        if not result.good:
            print result
 
system.tag.writeAsync(paths, values, myCallback)

```

Callback function gets called when the Gateway tells client what the result of the tag write is and then `if not result.good` I would do a system.util.sendMessage to make a popup with the `result.diagnosticMessage` to appear.

If it's not actually important to have it async though, you can do it with blocking code via writeBlocking. If you don't actually need async I would recommend using blocking code.

```python
tags = ['someTag1','someTag2']
values = [1,2]
results = system.tag.writeBlocking(tags, values)
errMsg = ''
for i, result in enumerate(results):
    if not result.isGood:
        # Curate err messages 
        errMsg += "Writing value %s to tag %s had issue %s %s"%(str(values[i]), tags[i], str(result), result.getDiagnosticMessage())
# Now show errMsgs to user

```

---

<div class="post-metadata">

**Author:** ![Olivier\_Canuel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/olivier_canuel/32/66088_2.png) [@Olivier\_Canuel](https://forum.inductiveautomation.com/u/Olivier_Canuel)\
**Post date:** [August 7, 2024, 2:18pm UTC](https://forum.inductiveautomation.com/t/how-to-check-if-user-has-right-to-write-a-variable-from-button-event-script/94243/3 "2024-08-07T14:18:22Z")

</div>

Hello, yes that looks like what I try to achieve ! I was not happy with the callback function of the writeAsync but the writeBlocking is doing what I want ! I think I was just using the Async thinking the Blocking was working the same way.. Anyway, thank you!

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [August 7, 2024, 2:49pm UTC](https://forum.inductiveautomation.com/t/how-to-check-if-user-has-right-to-write-a-variable-from-button-event-script/94243/4 "2024-08-07T14:49:24Z")

</div>

Oh great then I would highly recommend starting with writeBlocking always and only transfer to writeAsync if the situation really calls for it.
