The CreatorCon Call for Content is officially open! Get started here.

User with admin role still see the Cancel Change button even the condition stated specific access

bbf35621
Kilo Sage

Hello folks,

 

I got a requirement to add conditions for the OOTB UI action called Cancel Change. The requirements are only assigned to group users, or a user who has a change_manager role can see cancel change. I have added in UI action condition,

gs.getUser().isMemberOf(current.assignment_group) || gs.getUser().hasRole('change_manager') && new ChangeFormUI(current).isCancelAvailable()

The conditions work for non-admin users but the admin users who are not assigned to a group or have change_manager role are still able to see the Cancel Change button. How can I prevent admin users from seeing this button?

 

bbf35621_0-1726069317488.png

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

hasRole always returns true for admins.  Try this approach instead:

(gs.getUser().isMemberOf(current.assignment_group) || gs.getSession().getRoles().indexOf('change_manager') >-1) && new ChangeFormUI(current).isCancelAvailable()

The parenthesis around the OR condition ensures there's no mis-interpretation of order/priority

View solution in original post

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

hasRole always returns true for admins.  Try this approach instead:

(gs.getUser().isMemberOf(current.assignment_group) || gs.getSession().getRoles().indexOf('change_manager') >-1) && new ChangeFormUI(current).isCancelAvailable()

The parenthesis around the OR condition ensures there's no mis-interpretation of order/priority

That solved my issue! Thanks!

You are welcome!

Mayur2109
Kilo Sage

Hi @bbf35621 ,

 

You can add extra condition for restricting button to admins as;

gs.hasRole('itil,sn_change_write') && new ChangeFormUI(current).isCancelAvailable() && !gs.hasRole('admin')

 

Please check and Mark Helpful and Correct if it really helps you.

Regards,
Mayur Shardul

ServiceNow Rising Star 2024