Inbound Action: email.body_text and HTML
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2017 07:09 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2017 07:18 AM
Hi Jamie,
Please use toString()
current.description = email.body_text.toString();
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2017 07:54 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2017 06:13 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2017 06:38 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2017 06:46 PM
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.