- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2025 03:16 PM
Hello ServiceNow Experts,
I'm looking to see how I can fulfill this business requirement. I am trying to achieve an email notice that will be sent to approvers that contains links to attachments from the sc_req_item RITM record. While the script below works great, it does contain links that are attached on the RITM, but I would like to also include attachments from Type: Attachment variable. Here is the email script I used for now.
attachLinks();
function attachLinks() {
//Check for any attachments and add attachment links if they exist
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.getValue('sysapproval'));
gr.addQuery('table_name', 'sc_req_item');
gr.query();
if (gr.hasNext()) {
template.print("Attachments: <br />");
while (gr.next()) {
var attachLink = '<a href="' + gs.generateURL(gr.getTableName(), gr.sys_id) + '">' + gr.file_name + '</a>';
template.print(attachLink + "<br />");
}
template.print("<hr/>");
}
}
Now, the Email Notification that gets sent is a blanket Approval Request, and includes the syntax as ${mail_script:attachmentLink}. I want to be able to reference also the variables that are an attachment as a link to this email. I hope I do not need to reference each variable's sys ID to retrieve this since the email notification applies to other catalog items, but any thoughts on how to achieve this?
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 12:57 AM
Hi @GamNOW , Try this -
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Add your code here
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.getValue('sysapproval'));
gr.addEncodedQuery('table_nameLIKEsc_req_item');
gr.query();
if (gr.hasNext()) {
template.print("Attachments: <br />");
while (gr.next()) {
template.print("Hi");
var t = '<a href="' + gs.getProperty('glide.servlet.uri') + gs.generateURL(gr.getTableName(), gr.sys_id)+ '">' + gr.file_name + '</a>';
template.print(t + "<br />");
}
template.print("<hr/>");
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2025 12:57 AM
Hi @GamNOW , Try this -
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Add your code here
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.getValue('sysapproval'));
gr.addEncodedQuery('table_nameLIKEsc_req_item');
gr.query();
if (gr.hasNext()) {
template.print("Attachments: <br />");
while (gr.next()) {
template.print("Hi");
var t = '<a href="' + gs.getProperty('glide.servlet.uri') + gs.generateURL(gr.getTableName(), gr.sys_id)+ '">' + gr.file_name + '</a>';
template.print(t + "<br />");
}
template.print("<hr/>");
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 09:23 AM
Thank you GopikaP, this worked great!!