Need to query the download link of attachments on Notification Template

Bird1
Mega Sage

Hello

I need help. I am creating a notification template. I would like to add the download link of  "Add attachments" of record producer. How to?

 

 

find_real_file.png

1 ACCEPTED SOLUTION

Sai Kumar B
Mega Sage

Hi Author,

Try the below notification script and call it into the email body

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.sys_id);
   gr.query();
   if(gr.hasNext()){
      template.print('Attachments: \n');
         while (gr.next()) {
            var attachLink = '<a href="' + gs.getProperty("glide.servlet.uri") + gs.generateURL(gr.getTableName(),gr.sys_id) +  '">' + gr.file_name + '</a>';
            template.print(attachLink +  '\n');
         }
      template.print('<hr/>');
   }
}

If there are multiple attachments try the below in email script to download all of them in a ZIP file

template.print('Click on the link to download : <a href="https://'+gs.getProperty("instance_name")+'.service-now.com/download_all_attachments.do?sysparm_sys_id='+ current.sys_id+'">'+Attachments+'</a>');

View solution in original post

2 REPLIES 2

Sai Kumar B
Mega Sage

Hi Author,

Try the below notification script and call it into the email body

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.sys_id);
   gr.query();
   if(gr.hasNext()){
      template.print('Attachments: \n');
         while (gr.next()) {
            var attachLink = '<a href="' + gs.getProperty("glide.servlet.uri") + gs.generateURL(gr.getTableName(),gr.sys_id) +  '">' + gr.file_name + '</a>';
            template.print(attachLink +  '\n');
         }
      template.print('<hr/>');
   }
}

If there are multiple attachments try the below in email script to download all of them in a ZIP file

template.print('Click on the link to download : <a href="https://'+gs.getProperty("instance_name")+'.service-now.com/download_all_attachments.do?sysparm_sys_id='+ current.sys_id+'">'+Attachments+'</a>');