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

Ewan, I don't have an example script but I am happy to try to get you going.   Several questions though:


  1. How are the users replying to their old tickets?   Are those emails going to an internal email box that is then forwarded to ServiceNow?   I ask is if the email came from your old system, how will those be re-routed to ServiceNow.
  2. Are the old incidents being loaded into the incident table and a ServiceNow INC number is being set?   Out of the box the incident caller will receive an email from ServiceNow letting them know that an incident was opened on their behalf.   The users could reply to those emails instead.   With this there would be no additional scripting involved.

Michael,



First...Thank you!



The users are replying to the old tickets directly in email using the email address.   We are not using the forward option for email but direct email ingest.   The old system will no longer receive email.   So in other words.   When we rollover we are migrating all old tickets and they are referenced via a custom field similar to your example.   So all of the old tickets have both an INC ServiceNow number and an old ticket number.   The email replies from the old system would thus create new incidents if we don't figure out a way to link them to the new INC.



I will test to see if the emails automatically send.



Thank you for that.   In the meantime if you could by any chance provide some guidance I am still interested in my original request as we may still get some people that reply to the old emails.



Regards,



Ewan


Ewan, thanks for the information.   Since you aren't using a forward option, how will the reply reach ServiceNow?   Email today within your company comes from "oldsystem@yourcompany.com" and when users reply to that email, your old system receives the emails and processes them.   But after the cutover if emails to oldsystem@yourcompany.com aren't forwarded to ServiceNow, they will bounce back to the user.   Hopefully this makes sense.



So my post above is for the situation where you are forwarding the emails from the old email address and inbound email actions can look for something else other than the watermark that is generated by ServiceNow   to link to a ticket like a custom field with the old ticket number.


I have set up email to be received directly by ServiceNow without a forward.   When we are switching over it is clean.   No email will go to the old system.   The replies from the emails from the old system will go directly into ServiceNow and without any references create new incidents, even though the old incidents are in the system with both a reference field to the old ticket number and a new INC number generated by ServiceNow during the import.


OK great, just wanted to make sure I am clear how emails will reach ServiceNow.   Since these will be brand new emails without the ServiceNow incident number or watermark they will create new incidents by the out of the box inbound email actions, specifically the one called Create Incident.   So you will need to modify this rule with something like the following.   I took the out of the box action and modified it.   I don't know your exact old system numbering scheme so I just came up with something using Regex to look for that pattern.   You will see my comment explaining what this is so feel free to edit it based on that numbering scheme.



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



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


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_OLD_TICKET_FIELD_IN_SN", 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();


      }


} else {


      // Below is the out of the box code


      current.caller_id = gs.getUserID();


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


      current.short_description = email.subject;



      current.category = "request";


      current.incident_state = 1;


      current.notify = 2;


      current.contact_type = "email";



      if (email.body.assign != undefined)


          current.assigned_to = email.body.assign;



      if (email.importance != undefined) {


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


                  current.priority = 1;


      }



      if (email.body.priority != undefined)


          current.priority = email.body.priority;



      current.insert();


}



I hope this helps!   I did a quick test in my instance and it worked fine.