Attachment Variables posted in Approval Notifications
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2024 10:47 AM
Hi,
I read the community article for Attachment variables 'https://www.servicenow.com/community/itsm-articles/attachment-variable-making-attachment-mandatory-i... and followed the script to display an attachment variable in the Approval Notification.
In the Email Template for our approval notification, we already had a script to add sys_attachments for the ritms into the approval notification (works fine).
<mail_script>
printattachments();
function printattachments() {
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id',current.sys_id);
gr.query();
while (gr.next()) {
template.print('Attachment: <a href="http://'+gs.getProperty("instance_name")+'.service-now.com/sys_attachment.do?sys_id='
+ gr.sys_id + '">' + gr.file_name + '</a>');
}
}
</mail_script>
Based on the above article link, I attempted to add the script to grab the variable attachment and add it to the approval notification, but although when I test using background script to ensure that I'm grabbing the correct attachment sys_id, this script is not adding a hyperlink to the variable attachment.
var gattach = new GlideRecord('sc_item_option_mtom');
gattach.addQuery('request_item.sys_id',current.sys_id);
gattach.query();
while(gattach.next()) {
var gtype = new GlideRecord('sc_item_option');
gtype.addEncodedQuery('item_option_new.type=33^item_option_new.active=true^sys_id='+gattach.sc_item_option);
gtype.query();
while(gtype.next()) {
// gs.info('this is the value ' + gtype.item_option_new.name + ' value ' + gtype.value);
var grattach = new GlideRecord('sys_attachment');
grattach .addQuery('sys_id',gtype.value);
grattach .query();
while (grattach.next()) {
var attachLink = '<a href="' + gs.generateURL(grattach.getTableName(),grattach.sys_id) + '">' + grattach.file_name + '</a>';
template.print(attachLink + "<br />");
}
}
}
Any ideas what is wrong would be helpful.
Thanks,
Karen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2024 02:53 PM
Hi @Karen16
you can access variables in email script, You can simply use below code.
var grattach = new GlideRecord('sys_attachment');
grattach.addQuery('sys_id',current.variables.Attchment); // current.variables.variablename
grattach.query();
while (grattach.next()) {
var attachLink = '<a href="' + gs.generateURL(grattach.getTableName(), grattach.sys_id) + '">' + grattach.file_name + '</a>';
template.print(attachLink + "<br />");
}
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP