# Which User only supervisor role

**URL:** <https://forum.inductiveautomation.com/t/which-user-only-supervisor-role/74941>\
**Category:** Ignition\
**Tags:** ignition81, vision, scripting\
**Created:** [June 13, 2023, 7:16am UTC](https://forum.inductiveautomation.com/t/which-user-only-supervisor-role/74941 "2023-06-13T07:16:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Priyanka.Khandge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/priyanka.khandge/32/35989_2.png) [@Priyanka.Khandge](https://forum.inductiveautomation.com/u/Priyanka.Khandge)\
**Post date:** [June 13, 2023, 7:16am UTC](https://forum.inductiveautomation.com/t/which-user-only-supervisor-role/74941/1 "2023-06-13T07:16:45Z")

</div>

Hi Guys,

I have tried to switch the only supervisor role user using the following script but I'm not able to switch only supervisor role user.

Any idea how to fix this?

```auto
username = event.source.parent.getComponent("Username").text
password = event.source.parent.getComponent("Password").text

roles = system.user.getRoles("")
for role in roles:
	if 'Supervisor' in roles:
		system.security.switchUser(username, password, event)
	elif 'Supervisor' not in roles:
		system.gui.messageBox("Try again")

```

Thanks,  
Priyanka

---

<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:** [June 13, 2023, 9:07am UTC](https://forum.inductiveautomation.com/t/which-user-only-supervisor-role/74941/2 "2023-06-13T09:07:27Z")

</div>

> [@Priyanka.Khandge](#):
>
> `for role in roles:`

Can you try this,

```auto
username = event.source.parent.getComponent("Username").text
password = event.source.parent.getComponent("Password").text

roles = system.user.getRoles("")
if 'Supervisor' in roles:
	system.security.switchUser(username, password, event)
elif 'Supervisor' not in roles:
	system.gui.messageBox("Try again")

```

---

<div class="post-metadata">

**Author:** ![Priyanka.Khandge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/priyanka.khandge/32/35989_2.png) [@Priyanka.Khandge](https://forum.inductiveautomation.com/u/Priyanka.Khandge)\
**Post date:** [June 13, 2023, 9:12am UTC](https://forum.inductiveautomation.com/t/which-user-only-supervisor-role/74941/3 "2023-06-13T09:12:06Z")

</div>

Yes. I also try this way. facing the same issue. every role user switched.

---

<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:** [June 13, 2023, 9:13am UTC](https://forum.inductiveautomation.com/t/which-user-only-supervisor-role/74941/4 "2023-06-13T09:13:03Z")

</div>

Is this occurring for all users with other roles or no roles?  
also try print(roles)

---

<div class="post-metadata">

**Author:** ![Priyanka.Khandge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/priyanka.khandge/32/35989_2.png) [@Priyanka.Khandge](https://forum.inductiveautomation.com/u/Priyanka.Khandge)\
**Post date:** [June 13, 2023, 9:14am UTC](https://forum.inductiveautomation.com/t/which-user-only-supervisor-role/74941/5 "2023-06-13T09:14:43Z")

</div>

> [@Dharani\_T](#):
>
> Is this occurring for all users with other roles or no roles?

Yes. I have tried to switch user only Supervisor role.

---

<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:** [June 13, 2023, 9:15am UTC](https://forum.inductiveautomation.com/t/which-user-only-supervisor-role/74941/6 "2023-06-13T09:15:16Z")

</div>

Can u provide the results of print(roles)  
check out this:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/c/3c5792d3dc309e42504959710a5d1e595b453528.png)

---

<div class="post-metadata">

**Author:** ![Priyanka.Khandge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/priyanka.khandge/32/35989_2.png) [@Priyanka.Khandge](https://forum.inductiveautomation.com/u/Priyanka.Khandge)\
**Post date:** [June 13, 2023, 9:19am UTC](https://forum.inductiveautomation.com/t/which-user-only-supervisor-role/74941/7 "2023-06-13T09:19:28Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/8/283124fdbb48f1853ee31af08393f1c64e92ca72.png)

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/d/2d07c687a495279c30dd40be3800a711512ff8e9.png)

---

<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:** [June 13, 2023, 9:26am UTC](https://forum.inductiveautomation.com/t/which-user-only-supervisor-role/74941/8 "2023-06-13T09:26:48Z")

</div>

You meant to say, switch user must be enabled only if the user has supervisor role (only 1 role)?

---

<div class="post-metadata">

**Author:** ![Priyanka.Khandge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/priyanka.khandge/32/35989_2.png) [@Priyanka.Khandge](https://forum.inductiveautomation.com/u/Priyanka.Khandge)\
**Post date:** [June 13, 2023, 9:28am UTC](https://forum.inductiveautomation.com/t/which-user-only-supervisor-role/74941/9 "2023-06-13T09:28:19Z")

</div>

@Dharani_T Thank you so much for your response.

Resloved my problem using the following script.

```auto
reqRole = "Supervisor"
username = event.source.parent.getComponent("Username").text
password = event.source.parent.getComponent("Password").text
roles = system.security.getUserRoles(username, password)
if reqRole in roles:
	system.security.switchUser(username, password, event)
else:
	system.gui.messageBox("Try again")

```
