Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

If your notification is on sc_task then you can include the attachments from SC Task record into email notification

Use the Include Attachment checkbox as true

Regards
Ankur

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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

If your notification is on different table than sc_task then you will have to send the attachments as link in the email body by scripting it

Regards
Ankur

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

Hi Ankur,

Thank you for your response.

The notification is on the Approvals table. Can you please help me with a sample script? Or re-direct me to any article for it?

Thanks in advance

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