change state restrict users
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2022 08:24 AM
Hi can one helpme with the requirment
CHANGE: Restrict Users from Closing Change Records
No one, including the admin role, should be able to close a change. For Change States, "Closed Successful" and "Closed with Defects", only the Change Manager role should be allowed to set these states.
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2022 09:04 AM
Hi Sai,
Create a before BR on the change request table as below -
Conditions: State changes
Script:
(function executeRule(current, previous /*null when async*/ ) {
if (current.state == '3') // add the backend value for closed
{
gs.addErrorMessage('State cannot be changed to closed');
current.setAbortAction(true);
}
if ((current.state == '2' || current.state == '5') && !gs.getUser().hasRole('change_manager')) // add the backend value for Closed Successful OR Closed with Defects
{
gs.addErrorMessage('State cannot be changed to closed successful or closed with defects unless you are a change manager');
current.setAbortAction(true);
}
})(current, previous);
Let me know if you need further help.
Thanks
-Harneet Sital (ServiceNow Certified Technical Architect)
Request you to please mark my answer as helpful or correct based on the impact
Find all my ServiceNow articles here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2022 09:44 AM
Hi even the admin sould not be able to access it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2022 10:14 AM
This code is not working for people who has admin, my ticket is only change manager can able to edit those two fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2022 10:17 AM
Hi Sai,
The last condition still will be true for admins as they have change_manager role inherited if you want to go beyond that then use you can use this instead and try -
(function executeRule(current, previous /*null when async*/ ) {
if (current.state == '3') // add the backend value for closed
{
gs.addErrorMessage('State cannot be changed to closed');
current.setAbortAction(true);
}
if ((current.state == '2' || current.state == '5') && (!gs.getUser().hasRole('change_manager') && gs.getUser().hasRole('admin'))) // add the backend value for Closed Successful OR Closed with Defects
{
gs.addErrorMessage('State cannot be changed to closed successful or closed with defects unless you are a change manager');
current.setAbortAction(true);
}
})(current, previous);
Ideally, this should help, but play around with conditions the way you expect them and the logic should hold true.
Thanks
-Harneet Sital (ServiceNow Certified Technical Architect)
Request you to please mark my answer as helpful or correct based on the impact
Find all my ServiceNow articles here