Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Download file from link on Email body

Prudhvi Raj4
Tera Guru

Hello,

I want to create a link on email body and when user links on that link word file need to download, I am trying to include email script in the body but the it's not working. Can someone please suggest the way to achieve it.

 

Thanks,

Prudhvi 

2 ACCEPTED SOLUTIONS

shyamkumar VK
Kilo Patron

Hello @Prudhvi Raj4 

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>');

 

 

Please mark this as helpful and accept as a solution if this resolves your Ask.
Regards,

Shyamkumar

View solution in original post

Yes, I am doing the same but its not showing up the link on email, Do we need to load the attachment to sys_attachment table before if so how to load it which will work for the tasks?

View solution in original post

3 REPLIES 3

shyamkumar VK
Kilo Patron

Hello @Prudhvi Raj4 

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>');

 

 

Please mark this as helpful and accept as a solution if this resolves your Ask.
Regards,

Shyamkumar

Yes, I am doing the same but its not showing up the link on email, Do we need to load the attachment to sys_attachment table before if so how to load it which will work for the tasks?

yes attachment should exists in sys_attachment table in order to download

Please mark this as helpful and accept as a solution if this resolves your Ask.
Regards,

Shyamkumar