Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Convert email html body from multipart/alternative to UTF-8

tpeleg
Tera Expert

Hello experts,

 

I'm looking for a way to convert email html body to utf-8. (as sender cannot parse it before sending to SN side).

 

tpeleg_0-1699204691156.png

 

I tried to adjust  this piece html code which do working on the web:

function strip(html)
{
var tmp = document.createElement("DIV");
tmp.innerHTML = html;
return tmp.textContent||tmp.innerText;
}

alert(strip(document.body.innerHTML));

 

Inbound action code:

 

var finalb = strip(email.body_text);
    current.description = finalb;
   
    function strip(html) {
        gs.log("Tomer - html is " +html,"Tomer");
        var tmp;
        tmp.innerHTML = html;
        gs.log("Tomer - inner text is " + tmp.innerText,"Tomer");
        return tmp.textContent || tmp.innerText;
    }
    current.insert();
 
html is returning full html body but innerText is undefined.
 
any suggestion?
 
Thanks,

 

Tomer
5 REPLIES 5

@Anand Kumar P  thanks for your quick response, but still no luck 😞

 

 var htmlBody = email.body_text.toString();
    var plainText = htmlBody.replace(/<[^>]+>/g, '');
    var finalb = strip(plainText);
    current.description = finalb;

    function strip(html) {
        gs.log("Tomer - html before tmp " + html,"Tomer");
        var tmp = document.createElement("DIV");
        gs.log("Tomer - html after tmp " + html,"Tomer");
        tmp.innerHTML = html;
        return tmp.textContent || tmp.innerText;
    }
 
html looks cleaner but not printing log after var tmp = document.createElement("DIV"); line...