Truncate email replies to include only newest content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2015 08:25 AM
When someone replies to a ServiceNow-generated email, most inbound actions are set up to add the reply as a comment or work note to the ticket (e.g., incident) that includes the entire email body of the reply. This quickly grows the size of the email/comments when conversations go back and forth several times, often making the newest content difficult to find. Not having seen any other solutions for this problem, I developed my own using three simple ServiceNow objects.
- Custom system property - to establish a watermark to be used to determine where the new content ends
- Business rule - to write the watermark into the email
- Inbound action - to interpret the reply and truncate the content using the watermark
The watermark is a string that represents a unique pattern of characters that should not normally be found in an email response. The use of the system property allows you to both "activate" the watermarking and establish the string used as the watermark. I've chosen the string //--*--// as the watermark.
The business rule is a before insert/update rule on the sys_email table with the condition that "type" changes to "send-ready". I've also added some conditions that the "target table" is only those tables where a reply inbound action has been configured. When it runs, it retrieves the watermark from the system property and inserts it into a hidden div element at the beginning of the email body.
var mark = gs.getProperty('gaig.email.watermark.truncate_reply');
if (mark != '') {
var str1 = '<div style="display: none;">'+ mark +'</div>';
var str2 = current.body;
var result = str1.concat(str2);
current.body = result;
}
The inbound action then finds the watermark in the reply and removes everything after it, only posting the content before the watermark into the new comment/work note.
var body = email.body_text.toString();
var mark = gs.getProperty('gaig.email.watermark.truncate_reply'); //get the value of the watermark
if (mark != '') {
var truncBody = body.split(mark); //if there's a watermark, split the string at the watermark
body = truncBody[0].toString(); //keep everything before the watermark
}
current.comments = 'received from: ' + mail + '\n\n' + body;
The result is a significantly less-cluttered stream of information added to the ticket history.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2015 01:27 AM
One thing to note is that this code only works for top replies (i.e. mail clients that put the reply at the top). This is fine for 99% of email clients, but for users who do bottom replies (like some people in our third level teams...) it runs the risk of stripping out replies.
Preventing this only requires a small modification though.
Business Rule:
var mark = gs.getProperty('gaig.email.watermark.truncate_reply');
if (mark != '') {
var str1 = '<div style="display:none; display:none !important;">'+ mark +'</div>';
var str2 = current.body;
var str3 = mark;
var result = str1.concat(str2) + str3 + '\n\n';
current.body = result;
}
You could also just use 'var result = str1.concat(str2) + str1 + '\n\n'; However having a separate str3 like this leaves the bottom watermark visible on the email reply, which ensure that users enter their text after it.
Inbound rule:
var body = email.body_text.toString();
var mark = gs.getProperty('gaig.email.watermark.truncate_reply'); //get the value of the watermark
if (mark != '') {
var truncBody = body.split(mark); //if there's a watermark, split the string at the watermarks
body = truncBody[0].toString() + truncBody[2].toString(); //keep everything before and after the watermark
}
current.comments = "reply from: " + email.origemail + "\n\n" + body;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2016 10:20 AM
This should also be possible using default functionality in the system: Email Properties - Inbound Mail Configuration (glide.pop3.reply_separators)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2016 10:23 AM
(Or, for those doing a better job keeping up with the new versions, hah: Inbound mail configuration)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2021 07:29 AM
Since Quebec, you have the Email Reply Separator table and the sys_properties glide.pop3.reply_separators is deprecated.