How to Send attachments from Task in approval notification?

Kalyani
Tera Contributor

Hi All,

I need to send the attachments uploaded on a particular catalog task, as file attachments to the Approver.

Can anyone please help me to identify the exact task attachment from the sys_attachment table?

Any help would be appreciated.

Thank you.

1 ACCEPTED SOLUTION

Hi,

Sample email script if your email notification is on sysapproval_approver table

And you want to show sc_task attachment

Email Script:

Name:show_attachments_task_record

Script:

(function runMailScript(current, template, email, email_action, event) {

	// Add your code here
	// get attachment for all SC Tasks belonging to the RITM present for this Approval Record
	var sc_taskRecord = new GlideRecord('sc_task');
	sc_taskRecord.addQuery('request_item', current.sysapproval);
	sc_taskRecord.query();
	while(sc_taskRecord.next()){

		var gr = new GlideRecord('sys_attachment');
		gr.addQuery('table_sys_id', sc_taskRecord.getUniqueValue());
		gr.query();
		if (gr.hasNext()) {
			template.print("Attachments: <br />");
			while (gr.next()) {
				var url = gr.getTableName() + ".do?sys_id=" + gr.getValue('sys_id'); 
				var attachLink = '<a href="' + url +  '">' + gr.file_name + '</a>';
				template.print(attachLink +  "<br />");
			}
			template.print("<hr/>");
		}
	}

})(current, template, email, email_action, event);

Include in your notification like this ${mail_script:show_attachments_task_record}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Hi Ankur
Thank you very much for the help!

You are welcome

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

I have a scenario where in task 1 candidate will upload attachment on sn_hr_core_task and there is another task 2 on sn_hr_core_task and once this is inserted I have to send an email with attachment submitted by candidate on task 1 to manager. How to achieve this Could you please help me.

Thank you!

 

@Priya164 

2 ways

1) copy file to other task and include that file in email

OR

2) include link to that file and user will have to login to instance to download the file

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader