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
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

Anil Lande
Kilo Patron

Hi,

Please check below link:

https://community.servicenow.com/community?id=community_question&sys_id=48a7c36bdbd91f400e3dfb651f96...

https://community.servicenow.com/community?id=community_question&sys_id=28c994f9db4eeb007d3e02d5ca96...

https://servicenowguru.com/system-definition/email-notifications-system-definition/email-links-uri-u...

 

Use email script to add attachment links, you can refer above links for email script examples.

 

Thanks,

Anil Lande

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Sai Kumar B
Mega Sage
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>');