- 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-29-2016 10:34 AM
Hello Michael
Here is the Inbound Script we're using to either update existing non-watermarked records or create net new.
We're including a script to add an attachment if present on either create new or update existing....but when I add the attachment script in the update portion, it works for updates but breaks create new if no match found, meaning no new records are created.
I'm sure it's a syntax issue because all pieces work fine separately...Can you see what I'm missing here?
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);
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 reqItemRec = new GlideRecord("sc_req_item");
reqItemRec.addQuery("u_tracking_number_4", matchedNumber);
reqItemRec.query();
if (reqItemRec.next()) {
reqItemRec.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
reqItemRec.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, "sc_req_item", reqItemRec.sys_id);
}
else{
createRequest();
}
}
function createRequest() {
var cart = new Cart();
var item = cart.addItem('89312dae51881200e4b5b722d08d6956');
cart.setVariable(item,'req_for','a103bf0f6f999200fe09e82fae3ee4c6');
//var pos = email.body_text.indexOf('contact email');
//var pos1= email.body_text.indexOf('company');
var body = email.email.body_html;
var pos1 = email.body.organization;
var pos2 = email.body.customer;
var pos3 = email.body.telephone;
var pos5 = email.body.call_no;
var pos10 = email.body.type;
var body1 = email.body_text;
var body2 = body1.match (new RegExp('(?ms)(?<=Description:)(.*?)(?=Type:)', 'jg'));
var pos7 = body2[0];
var cust_act = email.body_text;
var cust_act1 = cust_act.match (new RegExp('(?ms)(?<=Solutions:)(.*?)(?=IOT)', 'jg'));
var pos12 = cust_act1[0];
var pos11 = email.body.priority;
cart.setVariable(item, 'short_description', email.subject.toString());
cart.setVariable(item,'user_company',pos1);
cart.setVariable(item,'customer_name', pos2);
cart.setVariable(item,'user_phone_number', pos3);
cart.setVariable(item,'ci', pos10);
cart.setVariable(item,'u_tracking_number_2', pos5);
cart.setVariable(item,'service_description', pos7);
cart.setVariable(item,'customer_priority', pos11);
cart.setVariable(item,'customer_action_log', pos12);
var rc = cart.placeOrder();
var ritmSysID = "";
var ritmRec = new GlideRecord("sc_req_item");
ritmRec.addQuery("request", rc.sys_id);
ritmRec.query();
if(ritmRec.next()){
ritmSysID = ritmRec.sys_id;
}
// var sc_request = new GlideRecord('sc_request');
// sc_request.addQuery('sys_id', rc.sys_id);
// sc_request.query();
// sc_request.next();
// if(sc_request.next()){
// sc_request.watch_list = 'joshagilman@gmail.com';
// sc_request.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, "sc_req_item", ritmRec.sys_id);
}
event.state="stop_processing";
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2016 11:49 AM
Your brackets are still messing you up a little with your IF statements. I cleaned up the code a bit and put the attachment code in as a function that can be called. Hopefully this works for you.
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);
if (JSUtil.notNil(matchedNumber)) {
var reqItemRec = new GlideRecord("sc_req_item");
reqItemRec.addQuery("u_tracking_number_4", matchedNumber);
reqItemRec.query();
if (reqItemRec.next()) {
reqItemRec.comments = "received from: " + email.origemail + "\n\n" + email.body_text;
reqItemRec.update();
copyAttachment(reqItemRec.sys_id);
} else {
createRequest();
}
event.state="stop_processing";
}
function createRequest() {
var cart = new Cart();
var item = cart.addItem('89312dae51881200e4b5b722d08d6956');
cart.setVariable(item,'req_for','a103bf0f6f999200fe09e82fae3ee4c6');
//var pos = email.body_text.indexOf('contact email');
//var pos1= email.body_text.indexOf('company');
var body = email.email.body_html;
var pos1 = email.body.organization;
var pos2 = email.body.customer;
var pos3 = email.body.telephone;
var pos5 = email.body.call_no;
var pos10 = email.body.type;
var body1 = email.body_text;
var body2 = body1.match (new RegExp('(?ms)(?<=Description:)(.*?)(?=Type:)', 'jg'));
var pos7 = body2[0];
var cust_act = email.body_text;
var cust_act1 = cust_act.match (new RegExp('(?ms)(?<=Solutions:)(.*?)(?=IOT)', 'jg'));
var pos12 = cust_act1[0];
var pos11 = email.body.priority;
cart.setVariable(item, 'short_description', email.subject.toString());
cart.setVariable(item,'user_company',pos1);
cart.setVariable(item,'customer_name', pos2);
cart.setVariable(item,'user_phone_number', pos3);
cart.setVariable(item,'ci', pos10);
cart.setVariable(item,'u_tracking_number_2', pos5);
cart.setVariable(item,'service_description', pos7);
cart.setVariable(item,'customer_priority', pos11);
cart.setVariable(item,'customer_action_log', pos12);
var rc = cart.placeOrder();
var ritmSysID = "";
var ritmRec = new GlideRecord("sc_req_item");
ritmRec.addQuery("request", rc.sys_id);
ritmRec.query();
if(ritmRec.next()){
ritmSysID = ritmRec.sys_id;
copyAttachment(ritmSysID);
}
}
function copyAttachment(reqID) {
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, "sc_req_item", reqID);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2016 01:31 PM
Awesome! THANK YOU!!!
On Mon, Feb 29, 2016 at 2:50 PM, michael.ritchie <
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2016 07:40 AM
Hi Michael....
I appreciate your help with this! However, I think the event-stop processing line is in the wrong place?
As it is, if an update is found, it will update the existing Incident however the OOB 'create incident' Inbound action is also triggered so we get:
1 - Existing Incident updated
2 - Net new Incident
I think I need to event stop processing lines for both the 'query/update' and 'create new' portions of the code but not sure how that would look.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2016 08:44 AM
Josh,
The order value of the inbound email actions might have something to do with your issue. What are the values of those for the OOB create incident and this rule? You may need to adjust that to prevent both from firing.