gs.hasRole('anyrole') return true for admin

Jagadeesh_Maddi
Tera Contributor

can anyone please tell me why gs.hasRole('anyrole') is giving true for the admin and not for the other and also how to override this case that it must apply for admin too can we actually do that ? 

2 ACCEPTED SOLUTIONS

Chaitanya ILCR
Giga Patron

Hi @Jagadeesh_Maddi ,

yes it's returns true for admin even when the role doesn't exist and it's the expected behaviour

 

GlideSystem - Global--> User has at least one of the passed-in roles. Also returns true if the user has the administrator role. 

 

to check if the user actually have the role you can use this 

 

gs.getUser().hasAssignedRole()

ChaitanyaILCR_0-1768923727785.png

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

View solution in original post

MohamedZ
Tera Sage

Hi @Jagadeesh_Maddi 

Admin has other roles too so it returns true.

Server side we don't have gs.hasRoleExactly hence this cant be used.

Here is community answer which can be used as workaround:

https://www.servicenow.com/community/developer-forum/gs-hasroleexactly-in-server-side-script/m-p/282...

 

Thanks and Regards,

Mohammed Zakir

View solution in original post

5 REPLIES 5

MohamedZ
Tera Sage

Hi @Jagadeesh_Maddi 

Admin has other roles too so it returns true.

Server side we don't have gs.hasRoleExactly hence this cant be used.

Here is community answer which can be used as workaround:

https://www.servicenow.com/community/developer-forum/gs-hasroleexactly-in-server-side-script/m-p/282...

 

Thanks and Regards,

Mohammed Zakir