Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Capturing Date/ Email sent from Inbound Action

jmcagod
Kilo Guru

Hello,

We have a requirement to capture the sent time of the email received.

Ie) 

Sender sent email at 9pm

ServiceNow received email at 9:05pm

We wanted to capture the 9pm.

The highlighted item below is the Date it was sent by the sender.

 

Thanks!

2 REPLIES 2

Tony Chatfield1
Kilo Patron

Hi, you will need to parse the email header for the date\time stamp using string methods and then convert to date time.

Formatting Date/Time values in ServiceNow Scripts - Developer Community - Article - ServiceNow Commu...
SimpleDateFormat (Java Platform SE 7 ) (oracle.com)

Unfortunately it is not possible to validate\test data based on a screenshot image, but something like.

//for testing*****************************************
var email = {"headers": "This is a test\nDate:Friday,18 August 2017 21:22:25 +0530\nsomeotherstuff"};

gs.info(email.headers);
//****************************************************

//get the start of the line we want
var indexStarts = email.headers.indexOf("Date:");
//get the end of the line we want
var indexEnds = email.headers.indexOf("\n", indexStarts);

gs.info('indexStarts ' + indexStarts);
gs.info('indexEnds ' + indexEnds);

//get the date\time detail using substring, we exclue 'Date:' by incrementing indexStart by 5 and also trim() any leading or trailing white space from the result
var myDate = email.headers.substring(indexStarts + 5, indexEnds).trim();

gs.info('myDate ' + myDate);

//Now instantiate glideDateTime and set the required format
var gdt = new GlideDateTime();
gdt.setDisplayValue(myDate, "E,dd MMMM yyyy hh:mm:ss Z");
var dateTimeForField = gdt.getDisplayValue();
gs.print(dateTimeForField);

Thank you, Tony. Your post was the spark that ignited an idea to reconsitute a [From, To, Subject, Date] text block from a sys_email record.