- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 08:42 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 09:08 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 09:08 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 09:41 AM
That solved my issue! Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 09:44 AM
You are welcome!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 09:19 AM
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