Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

petercawdron
Kilo Guru

When creating new records from an inbound email action, it can be handy to attach the original email to the record.

//This script will take contents from an inbound email and create an attachment on the created record from the inbound email action.   
var emailAsAttachment = new global.emailAsAttachmentUtil();
emailAsAttachment.create(email, current);

This Script Includes will add the inbound email as an attachment on the new

var emailAsAttachmentUtil = Class.create();
emailAsAttachmentUtil.prototype = {
	initialize: function() {
		this.newLineChar = "\n";   
		this.contentType = "text/html";
	},

	create: function(emailRec, currentRec){

		var emailDetails = "To: "+emailRec.to+ "\n";
		if(!gs.nil(emailRec.cc)){emailData.push("Cc: " + emailRec.cc);}
		emailDetails+= "Subject: " + emailRec.subject + "\n";
		emailDetails+= "From:"+ emailRec.origemail + "\n";
		emailDetails+= "X-Unsent: 1" + "\n";
		emailDetails+= "Content-Type: text/html" + "\n\n";
		emailDetails+= emailRec.body_html;
		
		var sysAttachment = new GlideSysAttachment();
		sysAttachment.write(currentRec, emailRec.subject+'.eml', "text/html", emailDetails);
	},

	type: 'emailAsAttachmentUtil'
};
Version history
Last update:
‎06-25-2019 04:06 PM
Updated by: