How to avoid creating duplicate tickets when forwarding an email
Email inbound action: Create Incident (Forwarded)
If you want to update the existing incident instead of creating a new one every time you forward emails, then this script could help:
SCRIPT
gs.include('validators');
var watermarks = email.body_text.match(/Ref:MSG.*/gi);
var refMsgArray = (watermarks) ? watermarks[watermarks.length - 1].split(":")[1] : false;
if (refMsgArray) {
var mark = new GlideRecord('sys_watermark'); // check for a watermark
mark.addEncodedQuery('number=' + refMsgArray);
mark.query();
if (mark.next()) {
var inc = new GlideRecord(mark.source_table); // get the incident record by the table name and sys_id
inc.get(mark.source_id); // use dot-walking to get the incident number
if (inc.isValidRecord()) { // checking if the record exists
inc.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;
inc.update();
}
}
} else {
current.caller_id = gs.getUserID();
current.comments = "forwarded by: " + email.origemail + "\n\n" + email.body_text;
current.short_description = email.subject;
current.category = "inquiry";
current.incident_state = IncidentState.NEW;
current.notify = 2;
current.contact_type = "email";
if (email.body.assign != undefined)
current.assigned_to = email.body.assign;
if (current.canCreate())
current.insert();
}
Explanation
The script prevents new tickets (duplicates) from being created when a user forwards an email from ServiceNow. So, the user feedback is going to be included in the existing ticket when a user forwards an email from ServiceNow. Otherwise (when the user forwards it without a watermark), the script creates a new INC
Note: forwarded emails will create new records by default.
Make use of this script if you want to avoid that and instead update the existing incident with the feedback of the user.
Reference:
- https://www.servicenow.com/community/developer-forum/inbound-action-forward-emails-aren-t-updating/m-p/1993375/page/1
- https://docs.servicenow.com/bundle/vancouver-platform-administration/page/administer/notification/concept/c_WorkingWithWatermarks.html
- https://www.servicenow.com/community/developer-forum/how-to-add-watermark-to-my-email/m-p/1497149
Comments
Post a Comment