Inbound Email Action: - Extract data from an html table

Dan Tolgyesi1
Tera Expert

Hi,

 

Is anyone able to help/advise.

 

I have set up an inbound action to create a requested item - I have managed to get this going but I am having an issue extracting the data from the email.

 

This contains an html table - and the data I want to extract (to complete catalog variables) is in the second column.

 

Has anyone done this before and is it possible?

 

Here attached examples of the image and html code

 

Thanks in advance.

Dan

9 REPLIES 9

Sanjeev Kumar1
Kilo Sage

Hi,


You need to parsing email. So first read email body and then split it and create an Array.



See following it may be help you.



Create User and Notify Manager and Location's Market Owner - ServiceNow Wiki


THank you for your response -- I will give it a go



cheers


Dan


ohhgr
Kilo Sage
Kilo Sage

Hi Daniel,



I worked on a similar requirement earlier and sadly "email.body.field_name" doesn't work as it does for plain mails.



I had to write a separate function that removes all HTML tags and unnecessary spaces to pull the data. It is something like below



  1. var emailRef = new GlideRecord('sys_email');
  2. emailRef.get("sys_id_of_email");
  3. removeSpacesFromEmails(emailRef);
  4. //function to set the font for all emails sent out to Arial with size as 2
  5. function removeSpacesFromEmails() {
  6. gs.print(emailRef.body);
  7.               emailRef.body = emailRef.body.substring(emailRef.body.search("first_field_name"), emailRef.body.search("known_text_entered_just_after_html_table"));
  8. gs.print(emailRef.body);
  9.               emailRef.body = emailRef.body.replace(/:/g, "");
  10.               var bodyArray = emailRef.body.split("<br /><br />");
  11. for(var i = 1; i < bodyArray.length; i=i+2) {
  12. gs.print(bodyArray[i]);


First column cell in my email has title "Associate Name", just as it is "Requested for (full name)" in the snapshot provided.



At the end of the code bodyArray contains all the text in the email. even indices(and 0th index) have the field_name while odd indices contain the values present.



Also, note that i ran above code in background script, so syntax will differ a bit if used in an email inbound action.



Check if above code is useful in your case.



Thanks,


Mandar


Thank you very much -



The first thing i tried was the standard email.body.XXXX and didn't work.



I will give your script ago and tweak where necessary.



Thanks,


Dan