- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2023 02:14 AM - edited 07-15-2023 02:15 AM
Hi,
I need to hide watermark from Outbound emails getting sent from ServiceNow. I have written a Business rule on Email log (sys_email) table, my script is below. The script works fine when tried with Background script but in Business rule it does not.
I tried adding a log and I cannot see watermark in my log but when I Preview the email it is still there.
Note: I know we have Omit watermark checkbox on notification record, but for my scenario I cannot use that feature and needs to be done with a script.
BR Details: Before Insert on sys_email Table
(function executeRule(current, previous /*null when async*/) {
var getEmailBody = current.body;
var removeWatermark = getEmailBody.match(/Ref:.*[A-Za-z0-9_.]/);
getEmailBody = getEmailBody.replace(removeWatermark, ' ');
gs.info('Email body ' + getEmailBody); // This gets print correctly with no watermark but while Preview it is still there.
})(current, previous);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2023 10:54 AM
Just quickly tested with:
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2023 02:26 AM
Hi there,
I don't see you actually replacing the current.body. Small mistake I guess.
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2023 02:27 AM
Also just tested your BR and only added:
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2023 10:42 AM
Thanks for pointing out. I might be sleeping while writing the above BR.
Can you please help me here , everything got removed except ">" which still stays as it is. How can I update my code to get rid of even this character from the email?
Regards,
Surbhi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2023 10:52 AM
I need to test with a proper regex. Though just debugging your removeWatermark:
*** Script: Ref:MSG0004891_vEKQtrFqAjA7R1xzqGmn</div></body></html
There's your issue. The regex is incorrect.
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field