Business rule to remove code from html email

Damian Martinez
Mega Sage

Hello Community,
does somebody have experience with java script?
I need to create a business rule that removes the following line from html code in emails:
<table style="padding: 0; margin: 0;" 0="" width="100%">
This line of code is causing email in the agent workspace not to render properly.
I don't have experience with java script.
your help is appreciate it.

Best Regard.

 

6 REPLIES 6

Hello @Anil Lande ,
sorry for the delay, I have been very busy with other things.
So I created a new business rule a you suggested above,  what when testing the result is the same.

This is the business rule:

find_real_file.png

 

find_real_file.png

 

The code in the script is this one:

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

if(current.body.indexOf('<table style="padding: 0; margin: 0;" width="100%" 0="">')>-1)
var newBody = current.body.replaceAll('<table style="padding: 0; margin: 0;" width="100%">','');// replace matching string from all positions
current.body = newBody;

})(current, previous);

it is a bit difference from the one you suggested because in your new var body you are still inserting the faulty code 0="" so I did not understand that.

Does this business rule and my code makes sense? or is it wrong and this is why it is not working?

Thanks again.

shloke04
Kilo Patron

Hi @Damian Martinez

Please write a Before Insert Business Rule on Email Table and use the script below:

BR Details:

Table Name: Email(sys_email)

When: Before insert

Condition: Type is Received

Script:

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

    // Add your code here
    var regex = /(<([^>]+)>)/ig;
    var body = current.body;
    var result = body.replace(regex, "");
	current.body = result;

})(current, previous);

 Screenshot of BR:

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke