Hide Watermark from Outbound Emails

Surbhi Srivasta
Tera Expert

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);

 

 

1 ACCEPTED SOLUTION

Just quickly tested with:

/Ref:[A-z0-9]*/
 
Looks oke.
 
Kind regards,
Mark

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

6 REPLIES 6

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

Also just tested your BR and only added:

current.body = getEmailBody;
 
Works oke. Theres one < left in the body, but basically the Ref is removed.
 
Kind regards,
Mark

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi @Mark Roethof 

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

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

LinkedIn