- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2020 07:28 AM
Hi All,
I need to send the attachments uploaded on a particular catalog task, as file attachments to the Approver.
Can anyone please help me to identify the exact task attachment from the sys_attachment table?
Any help would be appreciated.
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2020 07:43 AM
Hi,
Sample email script if your email notification is on sysapproval_approver table
And you want to show sc_task attachment
Email Script:
Name:show_attachments_task_record
Script:
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
// get attachment for all SC Tasks belonging to the RITM present for this Approval Record
var sc_taskRecord = new GlideRecord('sc_task');
sc_taskRecord.addQuery('request_item', current.sysapproval);
sc_taskRecord.query();
while(sc_taskRecord.next()){
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', sc_taskRecord.getUniqueValue());
gr.query();
if (gr.hasNext()) {
template.print("Attachments: <br />");
while (gr.next()) {
var url = gr.getTableName() + ".do?sys_id=" + gr.getValue('sys_id');
var attachLink = '<a href="' + url + '">' + gr.file_name + '</a>';
template.print(attachLink + "<br />");
}
template.print("<hr/>");
}
}
})(current, template, email, email_action, event);
Include in your notification like this ${mail_script:show_attachments_task_record}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2020 07:34 AM
Hi,
If your notification is on sc_task then you can include the attachments from SC Task record into email notification
Use the Include Attachment checkbox as true
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2020 07:35 AM
Hi,
If your notification is on different table than sc_task then you will have to send the attachments as link in the email body by scripting it
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2020 07:38 AM
Hi Ankur,
Thank you for your response.
The notification is on the Approvals table. Can you please help me with a sample script? Or re-direct me to any article for it?
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2020 07:43 AM
Hi,
Sample email script if your email notification is on sysapproval_approver table
And you want to show sc_task attachment
Email Script:
Name:show_attachments_task_record
Script:
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
// get attachment for all SC Tasks belonging to the RITM present for this Approval Record
var sc_taskRecord = new GlideRecord('sc_task');
sc_taskRecord.addQuery('request_item', current.sysapproval);
sc_taskRecord.query();
while(sc_taskRecord.next()){
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', sc_taskRecord.getUniqueValue());
gr.query();
if (gr.hasNext()) {
template.print("Attachments: <br />");
while (gr.next()) {
var url = gr.getTableName() + ".do?sys_id=" + gr.getValue('sys_id');
var attachLink = '<a href="' + url + '">' + gr.file_name + '</a>';
template.print(attachLink + "<br />");
}
template.print("<hr/>");
}
}
})(current, template, email, email_action, event);
Include in your notification like this ${mail_script:show_attachments_task_record}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader