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

Arun_Manoj
Mega Sage

Hi @nani1 ,

 

Based on your requirements, you want to enforce specific rules for incidents with priority P1/P2. Below is an example of how you can achieve this using a Business Rule in ServiceNow:

 

(function executeRule(current, previous /* previous */) { // Check if the incident priority is P1 or P2
if (current.priority == '1' || current.priority == '2') { // Check if the user is a member of the "Major Incident Management Team"
var currentUser = gs.getUser();
if (!currentUser.isMemberOf('major_incident_management_team')) {
// If the user is not a member of the team, prevent any updates
gs.addErrorMessage('Only members of the Major Incident Management Team can resolve P1/P2 incidents.'); current.setAbortAction(true); }
} })(current, previous);

Explanation:

  1. This Business Rule runs before an incident record is updated (executeRule function).
  2. It checks if the incident priority is P1 or P2 (current.priority == '1' || current.priority == '2').
  3. If the priority is P1/P2, it checks if the current user is a member of the "Major Incident Management Team" (currentUser.isMemberOf('major_incident_management_team')).
  4. If the user is not a member of the team, it prevents the update and displays an error message (gs.addErrorMessage).

For the second requirement, allowing other users to update the incident or assignee to the "Major Incident Management Team," you might want to handle it differently, as the current Business Rule restricts any updates if the priority is P1/P2. You might need to create additional logic to handle this requirement, possibly in a separate Business Rule or in the same Business Rule with additional conditions.

 

 

Thanks

Arun 

 

Please mark it as helpful, If the solution is fine.

Amit Pandey
Kilo Sage

Hi @nani1 

 

Can you paste the code in text format? I am unable to view from the screenshot.

 

Regards,

Amit

Im using below script in before BR. however its not allowing other user to update anything for P1/P2 incidnet;

Script:

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

     {

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

      current.setAbortAction('true');

    }

My Test case is to resolve the  p1/p2 incident when assignment group: "Incident Management Group"

Reject case:

if priority is P1/P2 and  assignment group is not "Incident Management Group"  through an error message and not allowing user to resolve the incident