Attachment to the notification

Bonam Yasaswini
Tera Contributor

I need a specific pdf document to be attached physically to the email notification when it's sent out. It shouldn't be a link to the pdf but it should be a physical file where the users can access the pdf without Servicenow access. How can it be achieved? Also, I need to know how to test the whether the attachment is included or not in email logs? Thanks in advance.

 

2 ACCEPTED SOLUTIONS

@Bonam Yasaswini 

yes it's possible. but the file has to be stored in some record.

I shared solution for something similar 2 years ago

Adding latest attachment from sys_attachment table to sys_email record 

1) create a system property and add your file to it

2) then create after insert BR on sys_email with condition as this

You change the table as sc_req_item

AnkurBawiskar_0-1736317663024.png

 

 

BR script

(function executeRule(current, previous /*null when async*/) {

        var propertyRecordSysId = ''; // give here the sysId of newly created system property record where file is present
	var s_Attach = new GlideRecord('sys_attachment');
	s_Attach.addEncodedQuery('table_sys_id=' + propertyRecordSysId);
	s_Attach.query();
	if(s_Attach.next()){
		var rec = new GlideRecord('sys_email_attachment');
		rec.initialize();
		rec.attachment = s_Attach.sys_id;
		rec.file_name = s_Attach.file_name;
		rec.source = 'notification';
		rec.content_disposition = 'attachment';
		rec.email = current.sys_id;
		rec.insert();
	}
})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

@Bonam Yasaswini 

yes if it comes in email attachment tab then it will be sent, it's OOB

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@Bonam Yasaswini 

the file has to be on the record from where notification is getting triggered.

You can use Include attachment checkbox on notification and the physical file will be sent

Can you share details notification is on which table?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Bonam Yasaswini
Tera Contributor

The notification trigger record will be the RITM when it's closed complete. The notification is on sc_request_item table.
Is there any way of adding it in the email instead of adding the file on every ritm rceord?

 

@Bonam Yasaswini 

yes it's possible. but the file has to be stored in some record.

I shared solution for something similar 2 years ago

Adding latest attachment from sys_attachment table to sys_email record 

1) create a system property and add your file to it

2) then create after insert BR on sys_email with condition as this

You change the table as sc_req_item

AnkurBawiskar_0-1736317663024.png

 

 

BR script

(function executeRule(current, previous /*null when async*/) {

        var propertyRecordSysId = ''; // give here the sysId of newly created system property record where file is present
	var s_Attach = new GlideRecord('sys_attachment');
	s_Attach.addEncodedQuery('table_sys_id=' + propertyRecordSysId);
	s_Attach.query();
	if(s_Attach.next()){
		var rec = new GlideRecord('sys_email_attachment');
		rec.initialize();
		rec.attachment = s_Attach.sys_id;
		rec.file_name = s_Attach.file_name;
		rec.source = 'notification';
		rec.content_disposition = 'attachment';
		rec.email = current.sys_id;
		rec.insert();
	}
})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

This is working. Also, I need to know how to test the whether the attachment is included or not in email logs. If it's included in the email attachments tab in the email log, will it be sent as an attachment?