How to remove simple email signature (text) from the inbound emails
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 01:22 AM
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:
The code does not work and I can still see the signature getting attached. Can someone debug this code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 02:37 PM
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.