Parsing email body into Inbound Email Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11 hours ago
Good day,
I'm trying to figure out how to get data out of a table in an email, and I've scoured multiple articles and utilised this already - How to read body text in Inbound EMAIL Flow - ServiceNow Community
However, it doesn't work for our instnace because the emails come in a tabled format, with no colons or anything defining the end of a word. Example -:
Title | |
First name | Test |
Last name | McTest |
When I tested the parsing utility in our sandbox, I was sending emails in and putting a - between Title and whatever the title is, and it would find it. However, we cannot re-format these emails (there's no option for us to do this without significant development time from another team) so I'm having to try and find a solution to this.
Could anybody suggest how we can achieve this please? I've seen various articles with scripts etc, but none of them work for us.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10 hours ago
Hi @StewartFletcher,
With some help from GenAI and testing, below is a snippet of code you can use as a starting point.
Note that I am assuming your table in your email is in a <table> tag.
var tableHTML = '<table width="427"><tbody><tr><td><p>Title</p></td><td> </td></tr><tr><td><p>First name</p></td><td><p>Test</p></td></tr><tr><td><p>Last name</p></td><td><p>McTest</p></td></tr></tbody></table>';
var rows = tableHTML.split('<tr>');
for(var i = 0; i < rows.length; i ++){
var cells = rows[i].split('<td>');
if(cells.length >= 3){
var key = cells[1].split('</td>')[0].replace(/<\/?[^>]+(>|$)/g, "");
var value = cells[2].split('</td>')[0].replace(/<\/?[^>]+(>|$)/g, "");
}
gs.info(key + " : " + value);
}The above will print something like:
*** Script: undefined : undefined
*** Script: Title :
*** Script: First name : Test
*** Script: Last name : McTest
Obviously, this will require more refinement but I think it will give you a good starting point.
Hope that helps, let me know if you have any questions.
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10 hours ago
Thanks James - that looks like it's tailored to that set of results though, and not a catch all?
Although I tried it and changed the values to my test data, and it didn't post anything for First name, but posted what looks like a sys id for Last name, so this doesn't work sadly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
So that's the script from the Parse Email Body Text action I was able to find, which works perfectly for anything OUTSIDE of the table, but cannot fathom exactly how to get it to see what's INSIDE the table tags
