Getting the sys_id of inbound email in inbound script

kchorny
Tera Guru

I need to capture the sys_id from an incoming email in a variable within an inbound action script.   I can get email.body_text, email.subject, etc. but email.sys_id comes back as 'undefined'.   email.getUniqueValue() doesn't work either (I didn't really expect it to) and I'm at a loss for what else to try.

Thanks in advance for any help.

1 ACCEPTED SOLUTION

Uncle Rob
Kilo Patron

The sys_email variable


According to docs, it appears that you might be able to do something like sys_email.sys_id.


View solution in original post

7 REPLIES 7

thx Robert! one more question: since the link you provided is not work, may i ask how can i find related documents (for example: i search keyword "sys_email" in https://docs.servicenow.com/ but it seems not that easy to find the information you've mentioned aboved)

sys_email.sys_id works for me inside of Inbound Email Action script. Thank you!

 

var emailGR = new GlideRecord('sys_email');

if (emailGR.get(String(sys_email.sys_id))) { // probably don't need the String

    // use emailGR

}

Louis22
Tera Contributor

 

 

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
	try {
	var greml = new GlideRecord('sys_email');
	greml.addQuery('uid', email.uid);
	greml.orderByDesc('sys_created_on');
	greml.query();
	if(greml.next()) {
		var strbody = grml.body.toString();
		gs.info('TEST:'+greml.sys_id);
	}
...