How to access data from a table in inbound action

SantanuKumar Sa
Tera Contributor

I want to pick values from a multirow table. 

SBU Head Email IDXYZ
SBUABC

 

how to retrieve the value as XYZ for field SBU Head Email ID

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@SantanuKumar Sa 

you will have to use string manipulation for this

What if the format changes later on? your script won't work then

Please discuss with your customer on this format

try something like this if you are using inbound email action

Get the values from HTML table from an email in a Inbound Action 

Inbound Email Action: Parse Data From Table in Email to Create Multiple Incidents 

Inbound Email Action: - Extract data from an html table 

check this if you are using inbound flow

Easiest way to Trigger Catalog Item Request via Inbound Email 

How to read body text in Inbound EMAIL Flow 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

shantanu_patel8
Mega Guru

@SantanuKumar Sa  Are you expecting the data to come in tabular format from emails? 

 

Please refer to : https://www.servicenow.com/community/itsm-forum/get-the-values-from-html-table-from-an-email-in-a-in...

 

Please mark the answer helpful and correct if it resolves your issue. Happy Scripting 🙂

 

-Shantanu

Robert H
Mega Sage

Hello @SantanuKumar Sa ,

 

Please copy the findValue function shown below into your Inbound Email Action script.

 

function findValue(key) {
    var re = new RegExp('<td[^>]*>' + key + '<\/td>[^<]*<td>([^<]+)<\/td>');
    var matches = re.exec(email.body_text);
    if (matches && matches.length === 2) {
        return matches[1];
    }
}

 

Given an inbound email with an HTML table like yours it will return the values you are looking for:

 

var email = {
    body_text: '<p>some text</p>' +
        '<table>' +
        '<tr><td>SBU Head Email ID</td>\n<td>XYZ</td></tr>' +
        '<tr><td>SBU</td><td>ABC</td></tr>' +
        '</table>' +
        '<p>some other text</p>'
};

gs.info(findValue('SBU Head Email ID'));
gs.info(findValue('SBU'));

 

Result:

XYZ
ABC

 

Regards,

Robert