logo

NJP

How to avoid creating duplicate tickets when forwarding an email

Import · Nov 14, 2023 · article

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:

View original source

https://www.dancovic.com/2023/11/inbound-action-forward-emails-arent.html