How to override IncidentUtils script Include to allow only major incident managers to close incident

Luke James
Tera Contributor

Good Afternoon All, 

 

I have a requirement where I need to only allow users with the major incident management role to be able to close a major incident in the esc portal. I can see that this is controlled within the IncidentUtils script include and IncidentUtilsSNC script include. 

 

How can amend this script include to allow for this behaviour? Can i override the function 

canCloseIncident in the IncidentUtilsSNC script include? 
 
Would really love the help on this as i'm stuck. 
 
Kind Regards, 
 
Luke
1 ACCEPTED SOLUTION

@Luke James - Please try the script below. I have not tested it but please try the script.

var IncidentUtils = Class.create();
IncidentUtils.prototype = Object.extendsObject(IncidentUtilsSNC, {
    initialize: function() {
        IncidentUtilsSNC.prototype.initialize.call(this);
    },
    /***************Custom changes****************/
      canCloseIncident: function(current) {
        if (current.incident_state != IncidentState.RESOLVED)
            return false;
        if (gs.hasRole("itil_admin"))
            return true;
        if (this._isMajorIncident(current))
            return (gs.hasRole("major_incident_manager"));
        else if (current.caller_id == gs.getUserID())
            return true;
        return false;
    },
    type: 'IncidentUtils'
});

IncidentUtils.isCopyIncidentEnabled = function(current) {
    var incidentUtils = new IncidentUtils();
    return incidentUtils.isCopyIncidentFlagValid();

};

IncidentUtils.isCreateChildIncidentEnabled = function(current) {
    var incidentUtils = new IncidentUtils();
    return incidentUtils.isCreateChildIncidentFlagValid();

};

 


If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni

View solution in original post

3 REPLIES 3

Saloni Suthar
Mega Sage
Mega Sage

Hi @Luke James ,

 

Yes, that is correct. You need to make changes to the IncidentUtils script include and override the canCloseIncident function to incorporate your condition.

 

 


If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni

Hi @Saloni Suthar , thanks very much for this. 

 

Any idea on how to do that? I've been struggling with the code for it in IncidentUtils. 

 

Kind regards, 

 

Luke

@Luke James - Please try the script below. I have not tested it but please try the script.

var IncidentUtils = Class.create();
IncidentUtils.prototype = Object.extendsObject(IncidentUtilsSNC, {
    initialize: function() {
        IncidentUtilsSNC.prototype.initialize.call(this);
    },
    /***************Custom changes****************/
      canCloseIncident: function(current) {
        if (current.incident_state != IncidentState.RESOLVED)
            return false;
        if (gs.hasRole("itil_admin"))
            return true;
        if (this._isMajorIncident(current))
            return (gs.hasRole("major_incident_manager"));
        else if (current.caller_id == gs.getUserID())
            return true;
        return false;
    },
    type: 'IncidentUtils'
});

IncidentUtils.isCopyIncidentEnabled = function(current) {
    var incidentUtils = new IncidentUtils();
    return incidentUtils.isCopyIncidentFlagValid();

};

IncidentUtils.isCreateChildIncidentEnabled = function(current) {
    var incidentUtils = new IncidentUtils();
    return incidentUtils.isCreateChildIncidentFlagValid();

};

 


If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni