create incident ui action

calvin_j_gerald
Giga Contributor

Has anyone created an incident for the customer or break fix request for customer/contact in the customer service management application?

9 REPLIES 9

Calvin,



Let me know if that answered your question. If so, please mark it as correct so that others with the same question can find it quickly in the future and that it gets removed from the Unanswered list. Thank you


Thanks for this info Chuck, it's been really useful.

I'm curious if this can be adjusted to create a specific catalog item, e.g. say that in in Maintain Items we have a specific item called 'Request help with your mobile', with specific fields, etc.

Do you know if it possible for the UI action script you provided to be adjusted to initialize the 'Request help with your mobile' item specifically.

Or as an alternative way of explaining what I'm asking, on the HRSM side of Service Now do you think it would be possible to put a UI Action which intializes a specific record producer?

Thanks,

Brett

calvin_j_gerald
Giga Contributor

Thanks everyone this was a big help!



Calvin


Let me know if I have answered your question. If so, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.


If you are viewing this discussion from your "inbox", use the "mark as correct" option under actions. If you are viewing it directly from the thread use the Correct Answer link (red with a star).


Thank you


Community Alums
Not applicable

Improving a bit Chuck's answer 2y ago, the following script is able to create incident through UI action where the incident will contain all details of the customer service case, displaying in the end a message addInfoMessage with the incident number. This approach turns UI Action clean and easily scalable. The logic would look like something like this, modifications required to meet your needs.

UI Action

// Action Name: create_incident
// Show Update: Yes
// Form button: Yes
// Condition: !current.isNewRecord() && current.incident_state != IncidentState.CLOSED

action.setRedirectURL(current);

var inc = (new NOWCaseUtils()).createIncidentFromCase(current);
if (inc.indexOf("Error") > -1) {
	gs.addErrorMessage(gs.getMessage("Could not create Incident."));
}else{
	gs.addInfoMessage(gs.getMessage("Incident {0} was created.", inc));
}

NowCaseUtils Script Include

var NOWCaseUtils = Class.create();
NOWCaseUtils.prototype = {
    initialize: function() {
    },
	createIncidentFromCase: function(objCase) {
		var caseInc = objCase.sys_id + "";
		var incident = new GlideRecord("incident");
		incident.initialize();
		incident.caller_id = objCase.assigned_to;
		incident.description = objCase.description;
		incident.short_description = objCase.short_description;
		incident.impact = objCase.impact;
		incident.urgency = objCase.urgency;
		incident.parent = caseInc;
		var incidentID = incident.insert();
		if (incidentID) {
			// we have to refresh the incident object at this point before updating
			var newCaseIncident = new GlideRecord("sn_customerservice_case");
			newCaseIncident.get(caseInc);
			newCaseIncident.state = 18;
			newCaseIncident.update();
			return "<a href='/incident.do?sysparm_query=sys_id=" + incidentID +"'>" + incident.number + "</a>";
		}
		return "Error: Could not create the incident";
	},

    type: 'NOWCaseUtils'
};

Thanks
Raf