IncidentUtils - help writing reopen override script include

gracjan
Tera Guru

I am trying to add an extensible script to the  IncidentUtils to change the default condition for the "Reopen Incident" UI Action. Please help me what am I doing wrong because it is not working?cond.PNGsave321.PNG

1 ACCEPTED SOLUTION

Aylee Andersen
Kilo Sage

Since you're not defining your new function within the class, you'll want to call it like a static function instead (ex: IncidentUtils.canReopenIncident()). You also shouldn't need "global." unless you're calling it from a scoped app. And you can drop line 23 in your function where you're initializing incidentUtils since you're not actually using that anywhere in the function.

 

Here is an OOB example using the static "isCreateChildIncidentEnabled" function defined in that same Script Include. Just replace "isCreateChildIncidentEnabled" with your own function name, "canReopenIncident". 

 

Screen Shot 2023-07-17 at 12.58.43 PM.png

 

Alternatively, you could move your function definition to the class (just under the comment at line 6) and call it the same way you are calling it currently (minus the "global." if the UI Action is in Global). 

 

 

var IncidentUtils = Class.create();
IncidentUtils.prototype = Object.extendsObject(IncidentUtilsSNC, {
    initialize: function() {
	IncidentUtilsSNC.prototype.initialize.call(this);
    },
    /***************Custom changes****************/	
    canReopenIncident: function(current) {
        return current.incident_state == IncidentState.RESOLVED;
    },
    type: 'IncidentUtils'	
});

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

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

 

 

 

 

Hope that helps!

View solution in original post

2 REPLIES 2

Aylee Andersen
Kilo Sage

Since you're not defining your new function within the class, you'll want to call it like a static function instead (ex: IncidentUtils.canReopenIncident()). You also shouldn't need "global." unless you're calling it from a scoped app. And you can drop line 23 in your function where you're initializing incidentUtils since you're not actually using that anywhere in the function.

 

Here is an OOB example using the static "isCreateChildIncidentEnabled" function defined in that same Script Include. Just replace "isCreateChildIncidentEnabled" with your own function name, "canReopenIncident". 

 

Screen Shot 2023-07-17 at 12.58.43 PM.png

 

Alternatively, you could move your function definition to the class (just under the comment at line 6) and call it the same way you are calling it currently (minus the "global." if the UI Action is in Global). 

 

 

var IncidentUtils = Class.create();
IncidentUtils.prototype = Object.extendsObject(IncidentUtilsSNC, {
    initialize: function() {
	IncidentUtilsSNC.prototype.initialize.call(this);
    },
    /***************Custom changes****************/	
    canReopenIncident: function(current) {
        return current.incident_state == IncidentState.RESOLVED;
    },
    type: 'IncidentUtils'	
});

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

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

 

 

 

 

Hope that helps!

gracjan
Tera Guru

There should be a colon instead of the equal sign but it worked.

canReopenIncident : function(current) {