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

@Ankur Bawiskar 

BR is on sys_email table

need to attach file to sys_email record from sys_attachment table.

 

Regards,

Reshma

@shaik11 

but the file is being fetched from which table?

Unless the file is attached to some table record like incident, problem, sc_task there will be no entry into sys_attachment.

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

@Ankur Bawiskar 

Actually we are creating a 'sys_attachment' file from flow designer actions.

 

Regards,

Reshma

@shaik11 

email is triggered from which table?

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

@Ankur Bawiskar 

we are triggering email through flow sys_attachment table

 

Regards,

Reshma