How to attach an inbound email as an attachment to an record from another table , if the inbound action is written to sc_req_item table.

samarasinghe
Kilo Contributor

Hi,

I have a requirement when inbound email received from service-now with the subject line with RITM numbr, it should create a new record in the table 'department' and that record should have that inbound email as an attachment.

This should be applied to New, reply , and forward emails.

 

So, when  writing an inbound email action to reply , Inbound email action's target table should be sc_req_item table. 

But the issue is now, this attachment not getting inserted into record created in 'department' table. Please help me to resolve this issue. Any help is very much appreciated!.

 

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

   

        //Add email as an attachment to the record	
        var attachment = new GlideSysAttachment();
        fileName = email.subject + '.eml';
        contentType = 'application/octet-stream';
        content = email.content_type + "\n" + email.headers + "\n\n\n\n" + email.body_text;

	
        attachment.write(dept_gr, fileName, contentType, content);
        dept_gr.insert();
		

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

 

This doesn't insert the attachment. Please help me to resolve this issue

1 ACCEPTED SOLUTION

Marcin20
Mega Guru

Hi,

I would propose to change the order:

 

 dept_gr.insert();

 attachment.write(dept_gr, fileName, contentType, content);

 

Best Regards,

Marcin

 

If my answer helped you in any way, please mark this answer as helpful and correct.

 

View solution in original post

1 REPLY 1

Marcin20
Mega Guru

Hi,

I would propose to change the order:

 

 dept_gr.insert();

 attachment.write(dept_gr, fileName, contentType, content);

 

Best Regards,

Marcin

 

If my answer helped you in any way, please mark this answer as helpful and correct.