Anyone had luck with hasRoleExactly?

bradfournier
Kilo Expert

I have a Form button UI Action that I'm trying to narrow a condition for. I currently have it written as:

g_user.hasRoleExactly('help_desk') && (current.state != '6' && current.state != '7' && current.state != '8')

This is not working. I have broken it up and tested each condition individually, all of the state checks work fine but the role check will not even work on its own. I have also tested using the basic hasRole() and that works fine, but due to admin privileges need to use hasRoleExactly. Does anyone have any experience using this function that might be able to give me some insight as to why this isn't working?

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

I stand corrected. As I mentioned earlier you can only use server side code in the conditions. Try my code as mentioned in my previous response



(gs.getSession().getRoles().indexOf('help_desk') >-1) && (current.state != '6' && current.state != '7' && current.state != '8')


View solution in original post

15 REPLIES 15

I thought it should work as well, that's why I was confused. I tested those two responses but still not working unfortunately. It is still showing me the button when I'm logged in as an admin when I shouldn't be able to see it.


Hi,



Try using :


gs.hasRole('help_desk') && (current.state != '6' && current.state != '7' && current.state != '8')



Got to know g_user is not to be used in UI Actions.


http://wiki.servicenow.com/index.php?title=GlideUser_(g_user)#gsc.tab=0



Thanks


Akhil


Hit Like/Helpful/Correct, if applicable.


Yeah, the g_user was my second incarnation of the script. Originally I had:



gs.getUser().hasRoleExactly('help_desk') && (current.state != '6' && current.state != '7' && current.state != '8')



but that was not working either. Trying to avoid using hasRole as I would like it not to be affected by admin privileges.


Abhinay Erra
Giga Sage

Note: by using getSession() it returns list of roles does not reflect any changes made during the current user session. To get the updated list of roles, the user must log out and log back in.


veena_kvkk88
Mega Guru

I just realized looking at Abhinay's reply and after a lil research:


hasRoleExactly() can only be used with g_user, only in client side scripts. hasRole(), on the other hand, can be used both with gs (server side) and g_user (client side)!