- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2015 02:13 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2015 03:06 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2016 06:37 AM
Hello Michael
Yep - I managed to get the script you provided to work for Incidents...perfect, thank you so much.
However I'm having a problem with the scripting format for creating requests via Inbound action - we're using the Cart API, but for some reason
the 'else' I have added to it - so 'query, is there a match?' (using your script), else 'Cart API/Create Request'. I'm not great with scripting - but I'm assuming I'm not making it clear to the else that the query is false when no match is found.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2016 06:32 AM
Josh,
Just so I am clear, you have an email that has a tracking number in the email subject and if a match you want to update an existing request. If not a match you want to create a new request? The code looks ok, though I only see part of it. What happens if tracking number doesn't match? Is a request not getting created? You can out a gs.log("got to createRequest function") on the first line within this function to make sure this function is getting called during processing. If it is then you may have an issue with your cart code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2016 11:02 AM
Sorry - just now getting back to this.
Well, I did have the incident query for matching ticket number and if not found, create a new Incident - but for some reason, it's stopped working. It will UPDATE existing if found, but won't create new if not found. Weird.
I got the Cart API/Request inbound action to work perfectly.
For testing purposes, I created the script line for line, but for some reason the 'else' is breaking...new incidents are not being created.
var numberPattern = "/[0-9]{7}/"; //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_company_incident_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();
}
} 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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2016 01:31 PM
You have an extra } bracket. The following should work
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_company_incident_number", matchedNumber);
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2016 12:51 PM
Ugh - too much staring at the screen.
Thank you so much for pointing this out, Michael - really appreciated.
It's working as expected