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
‎04-13-2015 09:06 AM
I did a similar thing few days back
var messageContent = email.body_text;
if (messageContent.indexOf("From")!=-1)
{
messageContent = messageContent.substring(0, messageContent.indexOf("From")).trim();
}
else
{
messageContent = messageContent.trim();
}
NOW messageContent holds the most recent message body,
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-08-2015 01:02 PM
Thank you so much for this idea.
Just one note - gmail ignores dsplay:none. To get around this I used the following syntax:
var str1 = '<div style="display:none; display:none !important;">'+ mark +'</div>';
I used both CSS syntax because Outlook didn't appear to like !important. This line of code works for gmail. The watermark will show in Outlook preview screen. It doesn't show when you open up the email in Outlook.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2015 08:15 PM
Hello Brian,
I had a question about this item for the Business Rule: "I've also added some conditions that the "target table" is only those tables where a reply inbound action has been configured."
I don't think I am quite understanding this portion of your solution, do you mean you added an "and" condition to the already existing "Type changes to send-ready" condition, that says "Target table [operator] [value]"?
For instance, if I only care about doing this for incident updates, would it just be "Target table is incident"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2015 04:37 AM
Hi Brian, that's exactly what I mean.