Trimm Inbound Email Script for Truncating Incoming Email Chain

New Developer_S
Giga Sage

Hi Community, 

 

I have a requirement where I need to truncate the email chain in incoming emails. Only last email should be visible. I have tried the below code for this and trimmed 'from '

#. This just works fine with my User id( I can see only the latest email -but not truncated part ) - This should be the expected behaviour.Which

 

But  When it is tested for other users, they are receiving the all email chain.  I am not sure, how to fix this. Can somebody help ? 

 

Here is my code for Update Incident ( Basically when User updates the incident, It should TRIMM all the incoming emails 'from' . I have tried email reply separators already , it does not help.

 

is There any better way to fix this ? 

 

here is my code :

 

 

 

gs.include('validators');

if (current.getTableName() == "incident") {

var body = email.body_text;

/*
* The name of the sender of the message is stored in a property
* called glide.email.username. We want to leverage this when
* we strip off the original message.
**/
var system_user_name = gs.getProperty("glide.email.username");

/*
* Now look for the 'From: <System Email>' tag, so we can strip
* off the chain. ( ['F', 'r', 'o', 'm',':', ' '] = 6 )
**/
var beginInbound = body.indexOf(system_user_name) - 6;

if(beginInbound >= 0) {
// Strip off the original message
body = body.substring(0, beginInbound).trim();
}

 

 

 

 

 

 

 

 

 

 

5 REPLIES 5

Dustin Spain
Tera Contributor

There is an OOB feature for truncating email chains in additional comments.
The options can be found under System Policy > Email > Email Reply Separators
I have a config record for Outlook and one for gmail:

DustinSpain_0-1711727546737.png


This feature is working for me in ITSM (incident), but It is not working for HR.  That is what I am currently trying to figure out.

What is your config for gmail? We have outlook replies sending only the reply but gmail is sending the entire conversation in the comments. 

This is my config for gmail:

Separator: ^(On\s(.{1,500})wrote:)

Type: Regex

DustinSpain_1-1721852848067.png

 

 

Thank you! We have that too and I cannot figure out why it is still posting the entire thread in the comments from an incident reply email. I just opened a case with ServiceNow to see.