Inbound email action - Remove Few URLs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2023 06:28 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2023 01:16 PM
Hi, unfortunately your post contains no clear details of your inbound email message format and so the community cannot provide targeted\specific advice, but normally you would use javascript string methods to exclude content in the body of an email message. Perhaps you could update this thread to include an example message (as plain text or xml) so that the community is in a better position to review and advise.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 07:59 AM
Hi,
Format is normal text. It is just a alert which is sending to ServiceNow to create/update a incident.
I have tried below method to exclude the link from body of the email , but it is not working
(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
current.short_description = email.subject;
var emailBody = email.body_text;
//Specify the link which needs to be excluded
var contentToExclude = "[https://example.com/v3/_v0k97X2SM]";
//Using replace() method to remove the specified content
emailBody = emailBody.replace('contentToExclude',' ');
//Update emailBody
current.body_text = emailBody;
current.description = current.body_text;
current.cmdb_ci = "c8a99c5687672950d82afcc6cebb35df"; // CI name
current.assignment_group = current.cmdb_ci.assignment_group;
current.work_notes = "[code]Received from: " + email.origemail + "\n\n" + email.body_html + "[/code]";
var sys_id = current.update();
logger.logInfo("Successfully updated " + current.number + " (" + sys_id + ")");
})(current, event, email, logger, classifier);
.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2023 10:50 PM
Hi, in your code current is a reference to the task\record being updated by the inbound action and OOB current.body_text does not exist for incident table; similarly current.description is a string field that might not be large enough to contain all email messages as size can vary.
Based on the code you have supplied you need to use your replace() method against either email.body_text or email.body_html and then populate this updated version of the variable into your work_notes.
eg
var emailBody = email.body_text;
//Specify the link which needs to be excluded
var contentToExclude = "[https://example.com/v3/_v0k97X2SM]";
//Using replace() method to remove the specified content
emailBody = emailBody.replace('contentToExclude',' ');
current.work_notes = emailBody;
But, while this will populate the content of the email into your work_notes\journal, the URL will still be visible in the e'mail' if it is shown in your activity stream.
If you need to remove the URL from the actual email message then I think your inbound action would need to lookup the sys_email record and update it, but I would not recommend altering received email messages as this would mean that they are no longer a source of truth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2023 06:50 AM
Hi Tony
Thank you for your help. I have tried the above coding but it is not working.
Still I am getting the link in work_notes. Is there any function I can use other than replace ?