# How to get roles of logged in user?

**URL:** <https://forum.inductiveautomation.com/t/how-to-get-roles-of-logged-in-user/90775>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [May 23, 2024, 7:10am UTC](https://forum.inductiveautomation.com/t/how-to-get-roles-of-logged-in-user/90775 "2024-05-23T07:10:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [May 23, 2024, 7:10am UTC](https://forum.inductiveautomation.com/t/how-to-get-roles-of-logged-in-user/90775/1 "2024-05-23T07:10:19Z")

</div>

Hi,

I would like to control few operations based on the logged in user's role.  
Button script:

```python
system.gui.messageBox("Only supervisors can overwrite")

```

Would like to display the above message if the user does not have 'Supervisor' role.  
We can get roles of usersource using system.user.getRoles('default'). But how to get the logged in user's role?

---

<div class="post-metadata">

**Author:** ![Ujwal\_Wankhede](https://avatars.discourse-cdn.com/v4/letter/u/4af34b/32.png) [@Ujwal\_Wankhede](https://forum.inductiveautomation.com/u/Ujwal_Wankhede)\
**Post date:** [May 23, 2024, 7:29am UTC](https://forum.inductiveautomation.com/t/how-to-get-roles-of-logged-in-user/90775/2 "2024-05-23T07:29:15Z")

</div>

I think this example from manual match your requirement

> **[system.security.getRoles | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-security/system-security-getRoles#code-examples)**
>
> Finds the roles that the currently logged in user has, returns them as a Python tuple of strings.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 23, 2024, 7:55am UTC](https://forum.inductiveautomation.com/t/how-to-get-roles-of-logged-in-user/90775/3 "2024-05-23T07:55:56Z")

</div>

> [@Dharani\_T](#):
>
> `system.gui.messageBox("Only supervisors can overwrite")`

If the user ever gets this message there is something wrong with your application.  
**Don't give the user options that can not be used!** Disable the button if the user does not have the correct roles.

---

<div class="post-metadata">

**Author:** ![Ujwal\_Wankhede](https://avatars.discourse-cdn.com/v4/letter/u/4af34b/32.png) [@Ujwal\_Wankhede](https://forum.inductiveautomation.com/u/Ujwal_Wankhede)\
**Post date:** [May 23, 2024, 8:28am UTC](https://forum.inductiveautomation.com/t/how-to-get-roles-of-logged-in-user/90775/4 "2024-05-23T08:28:42Z")

</div>

@Transistor You suggested a good point. But in that case, How will the user know or get information about why the button is disabled?

---

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [May 23, 2024, 9:04am UTC](https://forum.inductiveautomation.com/t/how-to-get-roles-of-logged-in-user/90775/5 "2024-05-23T09:04:52Z")

</div>

Yes,I am trying to popup message for this reason only

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 23, 2024, 9:11am UTC](https://forum.inductiveautomation.com/t/how-to-get-roles-of-logged-in-user/90775/6 "2024-05-23T09:11:15Z")

</div>

Option 1: Add a label to the main view, "Login as supervisor to edit."  
Hide the label when logged in.  
Option 2: Add a tooltip to the button when not logged in.  
Option 3: Display the Submit button but take the operator directly to the Login page. (Worst option if the user is not a supervisor as they have just wasted their time filling in the form.)
