How to parse inbound email body text in HTML format?

James218
Mega Guru

Hi All,

I hope someone can help me; I am trying to create a requested item automatically from an inbound email. I have a third party tool sending email message to my instance which contains the below information. The email is in html format and I need to get the values of each element. The variable:value (e.g. email.body.variable) approach does not work here since on each line, I have the <p> </p> tags, I cannot amend the email to be sent as plain text; Can someone share a script to get each value of the below information and store in a variable? Thanks in advance!

 

 

<HTML><BODY><p>A termination is due to take place please find below the pertinent information to enable IT to close the account:</p>

 

<p>Termination Date:23/08/2019</p>

 

<p>Preferred Name:EE8 MM8</p>

 

<p>Employee Class:</p>

 

<p>Job Classification:</p>

 

<p>Job Title:</p>

 

<p>Manager ID:28002596</p>

 

<p>Country:CHN</p>

 

<p>Location:Shenzhen</p>

 

<p>&nbsp;</p>

</BODY></HTML>

4 REPLIES 4

Bhavana Ramesh1
Tera Contributor

Hello James,

 

Did you get the solution for this, if so can you please share me the code i have the similar requirement.

 

Thanks and Regards,

Bhavana

Hi Bhavana,

I'm sure this is much later than anticipated and may not be relevant to you anymore, but I stumbled upon this thread and thought that I had the same issue. This thread had me believing that "value:variable" was not running on my HTML email format. I luckily had the ability to swap my e-mail to plaintext format but my log statements still showed my variable as "undefined" so I was going crazy.

WELL it turns out that inbound rules DO run on HTML emails. I just missed a clear note in the official ServiceNow document which was causing my issue...

Note: The action always generates a lowercase variable name. Also, this functionality does not work on reference fields.

May have been the same case in this thread if the inbound action was something like...

current.u_jobtitle = email.body.Job_Title; //would not work

current.u_jobtitle = email.body.job_titile; //would be correct as it is generated as a lowercase variable

Hopefully this helps someone. 

P_Dinesh Kumar
Tera Expert

Hi James,

 

Did you get the solution for this?