EmailUtils | Script Include | get last received email

PHOTO EMBED

Fri Oct 01 2021 15:13:25 GMT+0000 (UTC)

Saved by @mathiasVDD #javascript

getLastReceivedEmail: function(target) {
		var mail = new GlideRecord('sys_email');
		mail.addQuery('instance',target);
		mail.addQuery('type', 'received');
		mail.orderByDesc('sys_created_on');
		mail.setLimit('1');
		mail.query();
		if(mail.next()){
			return mail.sys_id;
		}
		else
			return;
	},
content_copyCOPY