Restrict user to resolve the incident

nani1
Tera Contributor

Hi Team,

I'm Trying to stop user resolving the incident which contains priority is P1/P2. its working but not meeting our Test Cases:

1)if priority is p1/p2  then it allow only "major incident management team" to resolve the incident. 

2)  Allow other users to update the incident or assignee to "Major incident management team to resolve the incident

currently below Before BR not allowing any user to raise a p1/p2  incidents or update anything when priority is p1/p2. 

let me know if any changes required in the BR or its a correct way to write the Before BR  for this request.

 

1)When to Run

nani1_0-1710850877953.png

 

2)Script:

nani1_1-1710850877993.png

 

let me if any error in my code. only "Major incident management" group allow to resolve the priory P1/P2 incidents

1 ACCEPTED SOLUTION

Hi @nani1 

 

Can you replace yours with the following code and try-

 

 

if (current.assignment_group != 'Incident Management Group') {
            if (current.state == '6') { 
                current.state = previous.state; // Rollback state change
                current.setAbortAction(true);
                current.addErrorMessage("Only the 'Incident Management Group' can resolve incidents with priority P1 or P2.");
            }
        }

 

Please mark my answer helpful and correct.

 

Regards,

Amit

View solution in original post

18 REPLIES 18

Mohit Kaushik
Mega Sage
Mega Sage

Hi @nani1 ,

 

You have to modify 3rd line in your code, instead of 'getUser' use getUser(). I can see there is a question with similar screenshots:
Restrict user to stop resolving the incident when ... - ServiceNow Community
Not sure, if you have used a different ID to create a duplicate question, but the screenshots look same.

 

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

we want to  stop the user  to resolving "P1/P2 incident if the assignment group is not "major Incident management". 

Below Script is also not allowing any user to update incidnet with p1/p2

if(gs.getUser().isMemberOf('Major Incident Management')==false)

     {

      gs.addErrorMessage("Incident can Resolved by only MIM Team.");

      current.setAbortAction('true');

    }

Deepak Shaerma
Kilo Sage

Hello @nani1 

To achieve your requirement, where incidents with Priority 1 (P1) or Priority 2 (P2) can only be resolved by members of the “Major Incident Management Team,” and while still allowing other users to update or reassign the incident. 
 
General Approach

1. Identify or Create a User Group: Ensure there is a specific group for the “Major Incident Management Team.” All users who are allowed to resolve P1/P2 incidents should be members of this group.

2. Define Business Rules: You’ll need to create rules within your system that:
- Prevent users who are not part of the “Major Incident Management Team” from resolving P1/P2 incidents.

Business Rule to Prevent Resolution by Non-Team Members:
- Navigate to System Definition > Business Rules and create a new rule.
- Apply the rule to the Incident table.
- Configure the rule to run “Before” an update.

(function executeRule(current, previous /null when async/) {

    // Check if priority is P1/P2 and there is an attempt to resolve the incident
    if ((current.priority == ‘1’ || current.priority == ‘2’) && current.state == ‘Resolved’) {
        var userGrp = new GlideRecord(‘sys_user_grmember’); 
        userGrp.addQuery(‘user’, gs.getUserID()); 
        userGrp.addQuery(‘group.name’, ‘Major Incident Management Team’); 
        userGrp.query(); 
        
        // If the current user is not a member of the Major Incident Management Team, prevent resolution
        if (!userGrp.hasNext()) {
            current.setAbortAction(true); // Prevents the update from going through
            gs.addErrorMessage(‘Only members of the Major Incident Management Team can resolve P1/P2 incidents.’);
        }
    }

})(current, previous);


Testing : Check Your Group Name and Test your requirements. This will helps you 
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help us a lot.
Thanks & Regards 
Deepak Sharma

Hello @Deepak Shaerma!

 

Would your script above be able to be utilized for restricting resolution of proposed or accepted major incidents to only members of a Major Incident Management Team? I've tried reworking it to check for major incident states (proposed or accepted) instead of priority 1/2, but I am not well versed with scripting and was unsuccessful.