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 04:01 AM
BR is on sys_email table
need to attach file to sys_email record from sys_attachment table.
Regards,
Reshma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 04:03 AM
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.
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-13-2023 04:13 AM
Actually we are creating a 'sys_attachment' file from flow designer actions.
Regards,
Reshma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 04:24 AM
email is triggered from which table?
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-13-2023 04:52 AM