Remove Watermark from email body of incoming emails

Developer3
Tera Expert

We get emails from third party vendor servicenow instance to my client instance related to vendor incident and service requests. As soon as the email hits the client instance, a call record has to be created. I configured an inbound email action for this but the incoming vendor email has watermark because of this my inbound action is not triggered and the email is getting ignored. Could anyone please let me know the script to remove watermark from email body.

I referred this post: https://community.servicenow.com/community?id=community_question&sys_id=bb064b61db1cdbc01dcaf3231f9619a6 but I am not sure on the code of how to remove the watermark from email body.

So any scripting help on this is really appreciated.

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

You can try below (untested) a business rule that runs before insert/update on sys_email table.

When to Run: Required conditions or recipient list to make it specific. Else it will run for all mail that are received.

Suppose, Subject contains ABC

Script:

(function executeRule(current, previous /*null when async*/ ) {

    var getwatermark = new GlideRecord('sys_email');
    getwatermark.query();
    if (getwatermark.next()) {
        var bodyhastext = getwatermark.body;
        bodyhastext = bodyhastext.replace(/MSG0042550/g, '');//Suppose my watermark is of form :  //Ref:MSG0042550 so it replaces it with empty
        getwatermark.body = bodyhastext;
        getwatermark.update();

    }

    //Ref:MSG0042550

})(current, previous);

 

You can use your own logic as per your watermark text. In case you can also use split or substring methods for removing watermark,

Note: This has high impact on the performance of system

View solution in original post

9 REPLIES 9

This is the same link i mentioned in my question.

Megha Padale
Giga Guru

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

You can try below (untested) a business rule that runs before insert/update on sys_email table.

When to Run: Required conditions or recipient list to make it specific. Else it will run for all mail that are received.

Suppose, Subject contains ABC

Script:

(function executeRule(current, previous /*null when async*/ ) {

    var getwatermark = new GlideRecord('sys_email');
    getwatermark.query();
    if (getwatermark.next()) {
        var bodyhastext = getwatermark.body;
        bodyhastext = bodyhastext.replace(/MSG0042550/g, '');//Suppose my watermark is of form :  //Ref:MSG0042550 so it replaces it with empty
        getwatermark.body = bodyhastext;
        getwatermark.update();

    }

    //Ref:MSG0042550

})(current, previous);

 

You can use your own logic as per your watermark text. In case you can also use split or substring methods for removing watermark,

Note: This has high impact on the performance of system

But we cannot run gr.update() on "before" business rule correct?

My Bad! It is not required. It should work without .update() as well as its before.

Only reason to avoid its usage it make it run twice & avoid unnecessary load which does not have any impact apart from performance but yes it is recommended not to use. Just try it without .update() once for a check.