Extract data from HTML tables from incoming emails?

daggupati
Tera Contributor

Hi Everyone,

I have requirement to parse out   the HTML tables and get that information put into separate fields. When the incoming emails are coming to our system, inbound actions will take the data in the incoming emails body and kept that data in the proper fields. In this picture this is the incoming email coming to Servicenow so i need to get the information of "street" kept that one in the field called "street" in the incident table. samething for other fields. I also read the couple of other articles but i couldn't figure it out.

@How can we extract data from tables in inbound email actions? @Inbound Email Action: - Extract data from an html table @Inbound email action to read data from HTML email

@chuck

find_real_file.png

Thanks in Advance.

9 REPLIES 9

kc99
Giga Expert

Hi Ram,



we have this same issue - did you find a solution for this?



Thanks,


Keiron.


kandasamykishor
Kilo Explorer

Try this.

 

var street,state,city;

var body = email.body_text;
body = body.replace('\t');
body = body.replace(/^(?=\n)$|^\s*|\s*$|\n\n+/gm,"");
var lines = body.split('\n');

for (i = 0; i < lines.length; i++)

{

          if(lines[i].indexOf('Street')!=-1)
          {

                state = lines[i];

           }           

          if(lines[i].indexOf('City')!=-1)
          {

              city = lines[i]

            }

           //continue for all other fields.

 }          

 

 

Jay Patel1
Tera Contributor

I have tried executing this and it works 100%

 

var a = email.body_text;

var start = a.indexOf("Street:");

var end = a.indexOf("City:");

var streetsubstr = a.substring(start +7, end);      //number of Char in "Street:" = 7//

var streetsubstr = streetsubstr..replace(/\s+/g, "");

current.u_street = streetsubstr;

Jay Patel1
Tera Contributor

.replace(/\s+/g, "");

Chavan AP
Kilo Sage

Hi Please checkout my article on this:

https://community.servicenow.com/community?id=community_article&sys_id=8dcdc538db50ccd0d82ffb2439961...

Glad I could help! If this solved your issue, please mark it as Helpful and Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****