How to Add latest attachment file to sys_email record from sys_attachment table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 02:34 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 06:05 AM
yes but the email has to be for some record right such as INC001 or SCTASK001 etc
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 03:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 03:50 AM
so the file will be on sc_task record and from there you need to copy?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader