Attachment over email

Hafsa1
Mega Sage

I have dynamic attachments associated with case table.

But I have notification on sysapproval table need to send email while notification generated with all attachment linked to case table.

how to achieve it.

 I have used  BR on "sys_email" table. But it not copying attachment.

GlideSysAttachment.copy('sn_customerservice_north_america_procurement', current.instance, 'sys_email', current.sys_id);
5 REPLIES 5

PritamG
Mega Guru

to send email notifications with attachments from the Case table when triggering notifications on the sysapproval table

Use GliseSysAttachmentProperly Ensure GliseSysAttachment.copy() uses correct table and sys_id references.

use following solution

 

var attachment = new GlideSysAttachment();
attachment.copy('case_table', case_sys_id, 'sys_email', current.sys_id);

 

Place the Business Rule after insert/update on sys_email. Ensure correct sys_id from the Case is referenced and consider filtering relevant attachments if needed before copying

 

Community Alums
Not applicable

Hi @Hafsa1 

we can try following code with After BR:

 

(function executeRule(current, previous /*null when async*/) {
// Get the case record associated with the current email (sys_email)
var caseRecord = current.instance; // This assumes `instance` field is the case reference on sys_email

// Ensure the case record exists
if (!caseRecord) {
return;
}

// Get the attachments from the case record
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_name', caseRecord.getTableName());
attachmentGR.addQuery('table_sys_id', caseRecord.sys_id);
attachmentGR.query();

// Copy each attachment to sys_email table
while (attachmentGR.next()) {
// Use GlideSysAttachment.copy to copy each attachment to sys_email
GlideSysAttachment.copy(attachmentGR, 'sys_email', current.sys_id);
}
})(current, previous);

 

suggestion: verify the sn_customerservice_north_america_procurement table  contains attachments linked via the sys_attachment table. The sys_attachment table holds the actual files, and they need to be linked to both the sn_customerservice_north_america_procurement and sys_email records.

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Hafsa1 

you can copy file from case record to approval record

OR

you can add file on sys_email directly

what BR did you write? share script and trigger condition screenshots etc

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

@Hafsa1 

Hope you are doing good.

Did my reply answer your question?

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