only lastest additional comments should send via email

New Developer_S
Giga Sage

Hi,

 I have a notification email  configured , for which I am looking for implementation ideas.

 

need solution for :  email should only send the latest additional comments .

 

•If mail is sent to customer  with text ABC( in additional comments ) , ( offcourse : it needs to be added to INC# history)

Email 1 outbound : ABC ( BODY TEXT)

•If customer replies later with text DEF, only the reply information DEF must be added

Email 2 : reply mail to Email 1 : Inbound Email : DEF ( BODY TEXT) ,  ABC - Should not be visible .

 

•Goal is to avoid having the original ABC message copied again, which would pollute the ticket history if there are numerous mails going back and forth and each time, the full message would be copied into the ticket again.

How to code this ? Can someone provide with code snippet ?

 

TIA

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@New Developer_S 

you can use email script and include that email script in email body.

Email script will fetch the latest comments and print it

Something like this

var fieldName = 'comments';

var rec = new GlideRecord('sys_journal_field');
rec.orderByDesc('sys_created_on');
rec.addQuery('name', current.getTableName());
rec.addQuery('element', fieldName);
rec.addQuery('element_id', current.sys_id);
rec.setLimit(1);
rec.query();
if(rec.next()){

template.print("Latest comments: "+ rec.value);

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

Where should we write this script ? is this Email notification scripts ? Inbound Email action Scripts ? Can we use Email Reply Seperators here ? Could you please advice how ?

 

TIA

 

@New Developer_S 

Email script.

Check this link and explanation

Scripting for email notifications 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Sachin Shinde
Tera Contributor

Hi Check the below thread.

How to get the most recent email body text and ign... - ServiceNow Community

 

Trail mail can be identified in the Body content using keywork "From:" 

You can use this logic to trim the comment after this key word.