Inbound Action: email.body_text and HTML

Jamsta1912
Tera Guru

Hello all,

I have an inbound email action set up against the incident table.

I'm populating the 'description' field using this:

current.description = email.body_text;

Standard so far, and I have a number of other inbound actions doing the same thing.

However, in this particular case the description field is being populated with the raw HTML of the inbound email, rather than just the actual text.

Any suggestions on why this might be happening?

Jamie.

18 REPLIES 18

sachin_namjoshi
Kilo Patron
Kilo Patron

Hi Jamie,



Please use toString()




current.description = email.body_text.toString();



Regards,


Sachin


Hi Sachin,


Thanks - I will try this, but it's curious that I've never had to do this previously. I've always just used email.body_text, so I think there's something about the particular emails that are being processed by this Inbound Action.


Hi Sachin,



It's still not working for me when I use body_text.toString().


I have this general javascript code from elsewhere, that extracts the text from HTML:



function getTextfromHTML(html) {


      var el = document.createElement( 'html' );


      el.innerHTML = html;


      return el.textContent;


}



However when I run this as part of an Inbound Action, I get an error: org.mozilla.javascript.EcmaError: "document" is not defined



Do you know if I can make use of the 'document' object in a script in ServiceNow? I appreciate, that question may warrant a post of its own.



Jamie.


Hi Jaimie,



You can use 'document' in ServiceNow but only client-side (in the browser), I believe.   Your Inbound Actions are running on the server and would not have the document object available.




-Brian


Hi Brian,



Thank you. I realised the error of my ways a few minutes after I'd posted - yes 'document' can only be used client side


So my next question is do you know if there's an equivalent I could do on the server side?



Jamie.