How to get all Attachments to append to the record.

ChrisMar
Tera Contributor

Issue:

If the "assigned_to" emails (A) requesting documentation from the incident and (A) responds with the attachment. The attachment will not append to the incident because (A) is neither the "assigned to" or "on behalf of"

 

I can see the attachment in the email record, but no action is being taken. How can I get all attachments to append to the record? 

1 REPLY 1

Sanika Subhash
Tera Expert

Hi Chris,

 

To ensure that all attachments from the email are appended to the incident record, you can modify the code as follows:


(function executeRule(current, previous /*null when async*/) {
var emailSysId = current.sys_id;
var grAttachment = new GlideRecord('sys_attachment');

grAttachment.addQuery('table_name', 'sys_email');
grAttachment.addQuery('table_sys_id', emailSysId);
grAttachment.query();

while (grAttachment.next()) {
var attachment = new GlideSysAttachment();
attachment.copy('incident', current.sys_id, grAttachment.sys_id);
}
})(current, previous);


This modified code retrieves all attachments associated with the email record and uses the `GlideSysAttachment` API to copy each attachment to the incident record. By doing so, all attachments, regardless of the sender or being "assigned to" or "on behalf of," will be appended to the incident.

Make sure to replace `'incident'` in the `attachment.copy()` function with the correct target table name if you are appending the attachments to a different table.

Note: Ensure that the user running the business rule has the appropriate access and permissions to copy attachments to the target record.

 

If it is helpful to you then please mark this as helpful or correct.

 

Thanks,

Sanika