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.

When ever we will send mail from outlook to ServiceNow this mail need to add as a attachment inINC .

Venkata Subbam1
Tera Contributor

Hello all ,

Requirement : When ever we will send mail from outlook to ServiceNow below activities need to perform .

 1. This mail need to be attached as a "Attachment" to the particular closed incident 

  2.  Mail body content need to updated in the work notes for that incident .

Could any one please suggest  me the solution for this requirement .

 

Thanks!

 

Regards,

Venkata

1 ACCEPTED SOLUTION

siva krishna M2
Tera Guru

Hello @Venkata Subbam1 ,

 

Create an inbound email action with Target table as "incident" and Action type as "Record Action" with below script under Actions tab

 

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
 
var emailcontent= "Subject"+email.subject+"\n\n"+"From: "+email.origemail+"\n"+"To:"+email.to+"\n"+"\n\n\n"+email.body_text;
// Implement email action here
var p = new GlideRecord('incident');
p.get(current.sys_id)
var k = new GlideSysAttachment();
k.write(p,"email_attachment.txt","text/html",emailcontent)
current.work_notes = email.body_text;
current.update();
 
})(current, event, email, logger, classifier);
 
                                                                       (or)
 
If you want the attachment in email format then you can use below code inside the function
 
var emailcontent= email.content_type+"\n"+email.headers+"\n\n"+email.body_text;
// Implement email action here
var p = new GlideRecord('incident');
p.get(current.sys_id)
var k = new GlideSysAttachment();
k.write(p,"emailattachment.eml","application/octet-stream",emailcontent)
current.work_notes = email.body_text;
current.update();
 
 

 

If it helps, Kindly click on "Helpful" and mark it as Accepted solution

View solution in original post

6 REPLIES 6

Hello @siva krishna M2 ,

Please find the below screen short for your reference.

 

Thanks!

Regards,

Venkata.

 

We tried this:

 

var emailcontent= email.content_type+"\n"+email.headers+"\n\n"+email.body_text;
// Implement email action here
var p = new GlideRecord('incident');
p.get(current.sys_id)
var k = new GlideSysAttachment();
k.write(p,"emailattachment.eml","application/octet-stream",emailcontent);
 
But the inbound email contains any attachments, they are not showing in the outlook attachment.