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

Hi @nani1 

 

Its strange as the above is working for me. There might be some other validations which is conflicting with this. 

 

You can try achieving it with onChange client script-

  1. Type: onChange
  2. Target Field: state.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
    var stateValue = '6';
    var groupSysId = 'SPECIFIC_GROUP_SYS_ID';
    var groupField = 'assignment_group';

    if (newValue === stateValue && g_form.getValue(groupField) !== groupSysId) {
        g_form.setValue('state', oldValue);
        alert("Only the 'Incident Management Group' can resolve incidents with priority P1 or P2.");
    }
}

 

Regards,

Amit

will try and let you know

Hi,

Below script is working now, actually i pick the wrong sys id of a group. 

if (current.assignment_group != 'SYS_ID OF 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.");
            }
        }
I need to restrict the same in list view, but in ACL how can i add condition's?

Hi @nani1 

 

Please mark my answer helpful and correct.

 

Regards,

Amit

How can we achieve same thing via client script?

 

I tried below but did not work - 

 

Script include - 

var CheckUserGroup = Class.create();
CheckUserGroup.prototype = {
   initialize: function() {
   },
   checkMembership: function(userId, groupName) {
       var gr = new GlideRecord('sys_user_grmember');
       gr.addQuery('user', userId);
       gr.addQuery('group.name', groupName);
       gr.query();
       return gr.hasNext().toString();
   },
   type: 'CheckUserGroup'
};

client script - 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
       return;
   }
   if (newValue == 9) {
       var userId = g_user.userID;
       var ga = new GlideAjax('CheckUserGroup');
       ga.addParam('sys_id', userId);
       ga.addParam('group_name', 'Incident and Problem Managers'); 
       ga.addParam('sysparm_name', 'checkMembership');
       ga.getXMLAnswer(function(response) {
           var answer = response.responseXML.documentElement.getAttribute("answer");
           if (answer == 'false') {
               g_form.setValue('state', oldValue);
               g_form.addErrorMessage('You are not authorized to reject this problem.');
           }
       });
   }
}