Inbound Email as Attachment on Call Record

nathanjulo43
Kilo Contributor

Hello!

In our instance (Helsinki), we currently have inbound emails generating Call records for our Service Desk to work and determine the appropriate path (Incident, Request, etc.).

On this inbound email action, I have attempted to add a script under the Action tab to attach the inbound email(.eml) to the Call record as an attachment. This is useful for our environment because in many situations the customer will cc others already working on, or have worked on in the past, whatever they are reporting or requesting. The Service Desk can view that original email and get a quick understanding of the escalation path for that record.

I am honestly a novice at scripting and I pull most of my scripts from the rock stars around this community! Do any of you have a few moments to take a look at the script below to let me know if I am completely out in left field with what I have up to this point?

var strEmailContent = email.content_type +"\n"+ email.headers;

        strEmailContent += "\n\n\n\n"+ email.body;

var sa = new GlideSysAttachment();

        sa.write(current, strFileName +".eml", " application/octet-stream ", strEmailContent);

Thank you so much for your time!

Nathan

1 ACCEPTED SOLUTION

sujalavemula
Kilo Guru

try this .It works for me .. it should work for you too



(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {




  // Implement email action here


  var strEmailContent = email.content_type +"\n"+ email.headers + "\n\n\n\n"+ email.body;


var sa = new GlideSysAttachment();




current.short_description = email.subject;


current.description =email.body_text;


// map fields that are mandatory or necessary'


sa.write(current, email.subject +".eml", " application/octet-stream ", strEmailContent);




current.insert();




})(current, event, email, logger, classifier);





hope this helps.


View solution in original post

14 REPLIES 14

sujalavemula
Kilo Guru

try this ..



var strEmailContent = email.content_type +"\n"+ email.headers + "\n\n\n\n"+ email.body;


var sa = new GlideSysAttachment();


var cr = new GlideRecord('new_call');


cr.initialize();


cr.short_description = email.subject;


cr.description =email.body_text;


// map fields that are mandatory or necessary'


sa.write(cr, email.subject +".eml", " application/octet-stream ", strEmailContent);


cr.insert();


Thank you, Sujala! Unfortunately, when testing this script I discovered this actually just creates an additional Call record with the email details instead of adding the .eml file that generated the Call record as an attachment.


Does this works for creating PDF as well?



Regards


Deepak


sujalavemula
Kilo Guru

try this .It works for me .. it should work for you too



(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {




  // Implement email action here


  var strEmailContent = email.content_type +"\n"+ email.headers + "\n\n\n\n"+ email.body;


var sa = new GlideSysAttachment();




current.short_description = email.subject;


current.description =email.body_text;


// map fields that are mandatory or necessary'


sa.write(current, email.subject +".eml", " application/octet-stream ", strEmailContent);




current.insert();




})(current, event, email, logger, classifier);





hope this helps.