Inbound Email Actions - able to match an existing incident based on a ticket number from previous ticketing system being migrated over to SN?

bcronrath
Kilo Guru

We are migrating over to SN from a previous ticketing system.   Part of the migration will involve tickets that are already open in the old system, and clients will be expecting to still be able to reply to the old ticket subject lines for those tickets and get a response.   I can get emails to update existing incidents in our service now dev instance if I include the SN incident number format in the subject line, so moving forward it should be fine, however for those other tickets that we will be importing in that include the old format of ticket numbers (does not have "INC" in the ticket format) is there a way we can script our inbound email actions for incident updates to check on a different style of ticket number format?

Best regards,

Brian

1 ACCEPTED SOLUTION

Many organizations choose not to import ticket data from the old system, but obviously in some cases that may be required.   If you need to do this, you could create a custom field with the old ticket number, or even prefix the short description with it.   Then your inbound email script could do a query in whatever field you choose to match that ticket number.   First you could need to parse the email subject for the old ticket number, then use that in your query to find the existing incident created.   I hope this makes sense.


View solution in original post

35 REPLIES 35

Hello Michael



The orders are 'ok'...70, 90, 100...with 100 being the standalone 'create incident'.



It just skips the 'stop processing event.   The one I have posted is for request...but same format for SC Request.




//Note: current.opened_by is already set to the first UserID that matches the From: email address

var numberPattern = "/[0-9]{7}/"; //Looking for # (1 occurrence) followed by 0-9 numbers (7 occurrences)


var reg = new SNC.Regex(numberPattern);


var matchedNumber = reg.match(email.subject);




//var sub1 = email.subject_text;


//var sub2 = sub1.match (new RegExp('[0-9]{7}'));


//var matchedNumber = sub2[0];




if (JSUtil.notNil(matchedNumber)) { //matchedNumber will be NULL if a match is not found in the email subject.


var incidentRec = new GlideRecord("incident");

      incidentRec.addQuery("u_company_incident_number", matchedNumber);


      incidentRec.query();


      if (incidentRec.next()) {


      incidentRec.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
      incidentRec.update();
var emailRec = new GlideRecord("sys_email");
emailRec.addQuery("uid", email.uid);
emailRec.orderByDesc("sys_created_on");
emailRec.query();
if(emailRec.next()){
GlideSysAttachment.copy("sys_email", emailRec.sys_id, "incident", incidentRec.sys_id);

}


}

else{


current.caller_id = gs.getUserID();


current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;


current.short_description = email.subject;


current.description = email.body_text;


current.assignment_group.setDisplayValue('a3a8e12f3701de0029156ec2b3990e27');






current.category = "Voice";


current.incident_state = 1;


current.notify = 2;


current.contact_type = "email";


current.impact = 2;


current.urgency = 2;


current.assignment_group.setDisplayValue('a3a8e12f3701de0029156ec2b3990e27');


current.u_company_incident_number = email.body.call_no;


//current.watch_list = 'DoNotReply_TestSystem@IOT.IN.GOV';


if (email.body.assign != undefined)
current.assigned_to = email.body.assign;
if (email.importance != undefined) {
if (email.importance == "High")
current.priority = 1;
}
if (email.body.priority != undefined)
current.priority = email.body.priority;
current.insert();

}


}


What release are you on?   Geneva has a useful "Stop Processing" checkbox on the inbound action itself.   If you are on Geneva try that.   But your setup sounds complicated and maybe we need to rethink what you are doing.   How are you distinguishing an incident from a sc_req_item vs a sc_request vs whatever other tables you have inbound email actions for?   Maybe these all need to be combined into 1.



The stop_processing is in the right place so if its not working you may want to check with Support to see if there is a known issue.


Hello Michael



Actually got it to work...had to insert 'stop processing' line in 2


different places - both in the update and in the create new. I had the


stop processing line in the same place in the update part but it didn't


work...I ended up removing and replacing with no indentation on that line.


I wouldn't have though that would have worked, but it did....so everything


works now and subsequent higher order Inbound actions don't trigger. Thanks


Josh



On Wed, Mar 9, 2016 at 5:51 PM, michael.ritchie <


I know this is an older thread, however this is exactly what i am trying to do only i need it to search for IN + 6 digits (IN123456) from the subject line. I am not great at coding so any suggestions would be great!


Thank you!




//       Note: current.opened_by is already set to the first UserID that matches the From: email address  


 


var numberPattern = "/[0-9]{6}/"; //Looking for 0-9 numbers, six numbers in total  


var reg = new SNC.Regex(numberPattern);  


var matchedNumber = reg.match(email.subject);  


 


if (JSUtil.notNil(matchedNumber)) { //matchedNumber will be NULL if a match is not found in the email subject.   If NULL we know this is a new email  


      var incidentRec = new GlideRecord("incident");  


      incidentRec.addQuery("u_client_ticket_number", matchedNumber); //Update this with your old ticket number field column name  


      incidentRec.query();  


      if (incidentRec.next()) {  


              incidentRec.comments = "received from: " + email.origemail + "\n\n" + email.body_text;  


              incidentRec.update();  



  }


      current.insert();  


}  


Desirae, no worries happy to help.   It just a slight modification to the numberPattern value:



//       Note: current.opened_by is already set to the first UserID that matches the From: email address



var numberPattern = "/IN\[0-9]{6}/"; //Looking for IN plus 0-9 numbers, six numbers in total


var reg = new SNC.Regex(numberPattern);


var matchedNumber = reg.match(email.subject);



if (JSUtil.notNil(matchedNumber)) { //matchedNumber will be NULL if a match is not found in the email subject.   If NULL we know this is a new email


      var incidentRec = new GlideRecord("incident");


      incidentRec.addQuery("u_client_ticket_number", matchedNumber); //Update this with your old ticket number field column name


      incidentRec.query();


      if (incidentRec.next()) {


              incidentRec.comments = "received from: " + email.origemail + "\n\n" + email.body_text;


              incidentRec.update();



  }


      current.insert();


}