I need help parsing data in an email body, please.

EWit
Tera Contributor

Hello all,

I've been tasked with parsing data out of an inbound email and turning them into variables within flow designer. Allow me to explain the process.

An email is generated by an AI and is sent to us. An inbound action grabs the email, and passes the body of the email to a catalog item as a multi-line text field via a cart API. Flow designer then needs to pull out the specific lines we are after and assign them to variables for use in the flow. Since the email is automatically generated, it always arrives in a predictable format, which is:

Page 1 Questions

 

1. question1

answer1

 

2. question2

answer2

(etc...)

The problem is that the underlying HTML code does not use a name:value format for the questions and answers, but instead uses <br> tags. My best attempt was using a for loop to build a string and stop when the string contains one of the questions. But this still does not extract the associated answer, and string concatenation is highly inefficient.

Ideally, I would like for my script to identify <br> tags so it would know when a line is over. Does anyone know how I might accomplish this?

Thank you in advance!

2 REPLIES 2

Ian Mildon
Tera Guru

The <br> in html equates to a '\n' carriage return in JavaScript.

I have multiple inbound email actions that are using the JavaScript "split" function to extract data from the email body and insert it into specified fields in the created record. Here is an example of the split function:

var getCluster = email.body_text;
var clusterName = [];
clusterName = getCluster.toString().split("Cluster Name  - "); //! there are two spaces between Name and -
var spl = clusterName[1].split("\n"); //* split at carriage return
current.cmdb_ci.setDisplayValue(spl[0].toLowerCase()); //* set the extracted name value

In this example I am wanting the value after the text "Cluster Name  - " so I make my first split there.

Next I only want the text from the first split to the following carriage return, so I make the next split at the carriage return. This means the value I want is now the value before the second split which in this example would be handled via setting the current cmdb_ci value.

The [1] equals anything after the split.

The [0] equals anything before the split.

 

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi EWit,

Would like to see the actual underlying html with the <br> tags.