Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Make incident active (reopen) when it's closed when new comment is added via mail

S_C_
Kilo Contributor

Hy! 
So whenever an incident is closed, and a client replies to it via email, we would like it to automatically open again ( so the state of the incident should change from closed to active ( in progress) 

So if the customer is replying to a ticket that is closed (the subject contains the reference id of the ticket) the comment gets posted into the ticket, but I would like it to be automatically reopened the ticket. 

Can someone help me on this subject? What do I need to do in order to get the desired workflow?

 

Thanks in advanced!

1 ACCEPTED SOLUTION

Aniket Sawant
Mega Expert

Hi,

set a condition to the "Update Incident" Inbound action to create a new Incident in case of the current one being already closed.

 

gs.include('validators');

 

 

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

 

var gr = current;

 

if(gr.state ==3 || gr.state==4){ //considering 3 is closed & 4 is closed complete

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();

}

}

 

 

Please try this code.

Please mark correct or helpful based on the impact.

Regards,

Aniket Sawant.

View solution in original post

5 REPLIES 5

ok, thanks for your help, I implemented your suggestion and it worked!