How to get roles of logged in user?

Hi,

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

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?

I think this example from manual match your requirement

2 Likes

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.

1 Like

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

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

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

3 Likes