logo

NJP

Creating a Download link for attachments in notification

Import · Nov 29, 2018 · article

Hi

You can use the below code to attach any attachments to email notifications, just open email scripts and add the code. Make sure to add the email script in your notification as ${mail_script:}

var gr =new GlideRecord('sys_attachment'); gr.addQuery('table_sys_id',current.sys_id; gr.query(); while(gr.next()){ template.print('Click on the link to download : '+ gr.file_name+''); }

}

the above code will create links for all the attachments present.

If you have attachment in some other table say in the approver records then use the below code :

printattachments(); gs.log("SYSID: "+current.sys_id); function printattachments(){ var d_id=""; var apr= new GlideRecord("sysapproval_approver"); apr.addQuery('sysapproval',current.sys_id); apr.query(); if(apr.next()){ d_id=apr.sys_id; gs.log("SYSID approver: "+d_id);// console.log("SYS ID: "+d_id); } var gr =new GlideRecord('sys_attachment'); gr.addQuery('table_sys_id',d_id);

gr.query();

while(gr.next()){ template.print('Click on the link to download : '+ gr.file_name+''); }

}

Thanks

SIddhant.

image

View original source

https://www.servicenow.com/community/developer-articles/creating-a-download-link-for-attachments-in-notification/ta-p/2325686