Automatically include attachments from TASK, on Email client , Client Template

Daniel O_Connor
Kilo Guru

Hi all,

I've created a Client Template for the first time, to be used in the Email Client I've enabled on a custom app. End users pretty happy with what it's doing (Really like how easy it was to make the template) but they have asked is it possible for the template to automatically include as attachments, any attachments present on the Task itself?

I can't see any obvious option for this. So to re-iterate, a TASK is logged with attachments, our users then use the email client to email a third party. And they want the attachments on the TASK to appear on the template, so they dont have to download and re-attach.

I'm not seeing how I make the attachments present on the TASK, populate onto the mail. (The attachment you see is an img from a signature that is to appear on every outbound mail in this app) 

find_real_file.png

16 REPLIES 16

Hi , 

 

you can try something like this . 

var grAttach=new GlideRecord('sys_attachment');
grAttach.addQuery('table_name','YOUR_TABLE_NAME');
grAttach.addQuery('table_sys_id','YOUR_RECORD_ID');
grAttach.query();
while(grAttach.next())
{
template.print ( 'Attachment: <a href="/sys_attachment.do?sys_id=' +grAttach. sys_id + '">' + gr. file_name + '</a>\n ' ) ;


}

 

this will bring all the attachments related to your record. 

 

 

Thanks, 

Mukesh Sharma

 

Hi Mukesh,

 

Do I just drop that code into the body section of the template? 

Just wondered if you ever found a solution for this, as years later...i'm in the same boat... if so please share! Thank you!

Mukesh Sharma
Giga Expert

Hi Daniel, 

 

You have to write email client script and copy the code in that email client script . after that you can call that email client script in your template by writing . 

 

${mail_script:script name}

 

to create email script click on 'notification email script' under  system notification section . 

 

Hope this was helpful. 

Think we are nearly there. Really appreciate your help, scripting isn't my strongest suit in ServiceNow

In your script 

var grAttach=new GlideRecord('sys_attachment');
grAttach.addQuery('table_name','YOUR_TABLE_NAME');
grAttach.addQuery('table_sys_id','YOUR_RECORD_ID');
grAttach.query();
while(grAttach.next())
{
template.print ( 'Attachment: <a href="/sys_attachment.do?sys_id=' +grAttach. sys_id + '">' + gr. file_name + '</a>\n ' ) ;



}

 

You have "YOUR_RECORD_ID" I don't understand this part. If the record is going to be different every single time, how can I define the record id? 

Or are you saying to define the sys id of the table there?