Capture email headers

gaidem
ServiceNow Employee

Here is a script I wrote to capture email headers and attach it as a related list to incidents:
Table: sys_email
Run: After update
Condition: current.instance.changes() && current.instance.sys_class_name=="incident"



var incID = current.instance;
var incREC = new GlideRecord('u_email_headers');
incREC.initialize();
incREC.u_task = incID;
incREC.u_header = current.headers;
incREC.insert();

3 REPLIES 3

Ringo000
Kilo Explorer

can i put this into an inbound email action.

All new emails are sent straight to a new call stage so i would need the headers to be attached to the new call.

Cheers
Richard


gaidem
ServiceNow Employee

current.headers in your inbound action should give you this information.


Ringo000
Kilo Explorer

sorry - do you mean

current.headers = email.headers?

what i have is below

would i slot this code into there?


var sid = gs.createUser(email.from);
gs.log('email from:' + email.from + ' created user:' + sid);

if ((email.copied.toLowerCase().indexOf('servicedesk@auckland.ac.nz') == -1)
&& (email.copied.toLowerCase().indexOf('studentservicesonline@auckland.ac.nz') == -1)
&& (email.copied.toLowerCase().indexOf('cecilhelp@auckland.ac.nz') == -1)
&& (email.copied.toLowerCase().indexOf('remedy@auckland.ac.nz') == -1)
&& (email.copied.toLowerCase().indexOf('askit@auckland.ac.nz') == -1))

{
// Process as per normal
current.description = "received from: " + email.origemail + " " + "(Cc's): " + email.copied + "\n\n" + email.body_text
current.short_description = "[" + email.direct +"]" + " " +email.subject ;


current.u_requestor = sid;
current.opened_by = sid;

current.contact_type = "email";
current.insert();
} else {
// Sent via CC line... reject.
var userRec = new GlideRecord('sys_user');
if (userRec.get(sid)) {
gs.eventQueue('inbound.copied', userRec, sid, email.subject);
}
}