gs.hasRole('admin') - role check not working in UI Action condition

kagarwni
Kilo Expert

Hello Community Members,

I am fairly new to ServiceNow and am stuck at a point where I cant understand the approach that I am following is correct or not.

I am trying to display a button that redirects to different ESS page based on certain condition.

This button should only be visible to a certain group of users having role abc.

I created a UI Action with Form Button checked .

In the condition if I try to write 1==2 , the button is not visible for admin . So the hiding thing is working .

However, if I type gs.hasRole('admin123') assuming admin123 is a role that admin does not have, the button is not getting hidden.

Could anyone please help/guide on this ?

Sample code in Script

if (condition==true)

    action.setRedirectURL('https://dev1234.service-now.com/incident.do?sys_id=-1&sysparm_query=active=true&sysparm_stack=incide...

  else

action.setRedirectURL('/ess/main.do');

Regards

Nitin

1 ACCEPTED SOLUTION

srinivasthelu
Tera Guru

Hi Nitin,



Admin is super user. He satisfies all the roles in the system.



This thread Server-side "hasRoleExactly" in ServiceNow   has a good example on how to test hasRoleExactly at serverSide



Thanks


Srinivas


Mark this response as helpful/correct if it does so


View solution in original post

2 REPLIES 2

srinivasthelu
Tera Guru

Hi Nitin,



Admin is super user. He satisfies all the roles in the system.



This thread Server-side "hasRoleExactly" in ServiceNow   has a good example on how to test hasRoleExactly at serverSide



Thanks


Srinivas


Mark this response as helpful/correct if it does so


Thanks a lot Srinivas.


I was testing this against a wrong user.


The article you shared helped.




Regards


Nitin