Which User only supervisor role

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?

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

Can you try this,

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")

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

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

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

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

image

image

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

@Dharani_T Thank you so much for your response.

Resloved my problem using the following script.

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")
1 Like