How to Add latest attachment file to sys_email record from sys_attachment table

shaik11
Tera Expert

Hi All,

 

Actually, My task is to add latest created attachment file from "sys_attachment" table to "sys_email" record which we are creating automatically using Email Notification.

To attach latest attachment file are using 'after Business rule' to achieve it. But not working as expected, it is attaching multiple files to sys_email record.

Using Code:

(function executeRule(current, previous /*null when async*/) {

var gr= new GlideRecord('sys_attachment');

gr.addEncodedQuery('file_name=Servers.csv^table_name=sys_attachment');
gr.orderByDesc('sys_created_on');
gr.setLimit(1);
gr.query();
if(gr.next())

{
var copyAtt = new GlideSysAttachment();
copyAtt.copy('sys_attachment', current.sys_id,'sys_email', current.sys_id);

}

})(current, previous);

 

Please provide inputs to achieve my requirement.

 

Regards,

Reshma

12 REPLIES 12

@shaik11 

yes but the email has to be for some record right such as INC001 or SCTASK001 etc

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

It is SCTASK Record

 

Regards,

Reshma

@shaik11 

so the file will be on sc_task record and from there you need to copy?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader