How do I create a new incident from an email response to a closed incident?

ewanh
Kilo Expert

Current State:

When someone replies to a Closed (Not Active) incident it updates that incident and does not change the state.

Desired State:

When someone replies to a Closed (Not Active) Incident it creates a new incident

Is there a standard or recommended solution for this?

1 ACCEPTED SOLUTION

Brian Dailey1
Kilo Sage

Hi Ewan,



Here is one way you can open a new Incident in response instead of updating a closed INC...



Look in your Inbound Email Actions and find the one(s) used to Update Incidents, it should have the email Type set to 'Reply' (or possibly 'Forward') instead of 'New'.  



  1. At the beginning of your IEA script, perform a check to see if the ticket has been closed (check whether it's active, or look for specific states):

    if(current.active == false){
        ...
    }
  2. If the condition matches, just create a new Incident using a GlideRecord and fill in the blanks with info from your email and the existing closed Incident, I'd set the existing INC as the parent.

    if(current.active == false){
        var gr = new GlideRecord('incident');
        gr.initialize();
        gr.opened_by = email.from_sys_id;
        gr.caller_id = email.from_sys_id;
        gr.description = email.body;
        gr.short_description = email.subject;
        gr.parent = current.sys_id;
        ... (grab some other relevant info from your existing INC using 'current')
        gr.insert();
        (avoid the 'current.update()' statement somehow using a break, return, etc.)
    }
    else{
        (perform your normal IEA update code)
        ...
    }



See how that works out for you.




Thanks,


-Brian


View solution in original post

6 REPLIES 6

For some reason this is not working for me.



In the Email logs I have "Skipping 'Update Incident (BP)', did not create or update incident"



gs.include('validators');




if (current.getTableName() == "incident") {



var gr = current;



if(gr.active == false){


gs.eventQueue("incident.Closed", gr, gr.state, previous.state);



var ni = new GlideRecord('incident');


ni.initialize();


ni.caller_id = email.from_sys_id;


ni.description = email.body;


ni.short_description = email.subject;


ni.incident_state = IncidentState.NEW;


ni.notify = 2;


ni.contact_type = "email";



if (email.body.assign != undefined)


ni.assigned_to = email.body.assign;




if (email.importance != undefined) {


if (email.importance.toLowerCase() == "high")


ni.priority = 1;


}




if (email.body.priority != undefined)


ni.priority = email.body.priority;



ni.insert();


}


else{


if (email.subject.toLowerCase().indexOf("please reopen") >= 0 && gr.state != 0)


gr = new Incident().reopen(gr, email) || gr;



gr.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;




if (gs.hasRole("itil")) {


if (email.body.assign != undefined)


gr.assigned_to = email.body.assign;



if (email.body.priority != undefined && isNumeric(email.body.priority))


gr.priority = email.body.priority;


}


}


gr.update();


}



Any ideas?



Thank you in advance


Hi Brian,

I've been attempting to add your code to our existing Update Incident (BP) inbound action, and haven't yet met with success, likely because of my poor scripting. Is it possible you can spot what I've done wrong in the below?

gs.include('validators');

if (current.getTableName() == "incident") {
	
	var gr = current;
	
	if(current.active == false){
    var gr = new GlideRecord('incident');
    gr.initialize();
    gr.opened_by = email.from_sys_id;
    gr.caller_id = email.from_sys_id;
    gr.description = email.body;
    gr.short_description = email.subject;
    gr.parent = current.sys_id;
    gr.insert();
	
}
else{
	
	if (email.subject.toLowerCase().indexOf("please reopen") >= 0)
		gr = new Incident().reopen(gr, email) || gr;
	
	gr.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
	
	if (gs.hasRole("itil")) {
		if (email.body.assign != undefined)
			gr.assigned_to = email.body.assign;
		
		if (email.body.priority != undefined && isNumeric(email.body.priority))
			gr.priority = email.body.priority;
	}
	
		gr.update();
}
}