Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to remove simple email signature (text) from the inbound emails

vidhya_mouli
Tera Sage

I have to remove signatures from inbound email before creating incident from it.

 

I have written the following script in the Inbound Email Action

 

(function process(/* GlideInboundEmail */ email, /* GlideRecord */ incident, /* Optional: GlideEmailMimeHeader */ mimeHeader) {
    // Get the email body from the email object
    var emailBody = email.getBodyText();

    // Remove common email signature patterns using a regular expression
    emailBody = emailBody.replace(/--\s*\n.*/g, ''); // Replace lines starting with "--" and following text

    // Update the email body in the email object
    email.setBody(emailBody);

})(email, current, email.headers);

 

And this is my trigger:

Remove-Email-Signature-Inbound-Email-Actions-ServiceNow.png

 

The code does not work and I can still see the signature getting attached. Can someone debug this code?

1 REPLY 1

Tony Chatfield1
Kilo Patron

Hi, I do not believe that you can update the email object in this manner and normal process would be to set the current.comments or current.work_notes of the target record directly from your updated variable in your inbound action IE

current.comments = emailBody;


If you want to alter the received sys_email record you would need to use a before insert BR and GlideRecord to lookup and update the sys_email record, but I would not recommend altering a received message in this manner as negates the validity of the message for auditing purposes.