logo

NJP

Copy attachments to Email Client Template (...)

Import · May 04, 2020 · article

For those who are frequent users of Email Client Template image have you come across a scenario where you need to send the same attachments from incident/change or any table where you have Email Client template enabled on?

If so, I guess the approach being used would be download the attachments first & then get it attached to the Email Client. It may time consuming as it requires unncessary downlad first & then attach again. To remove the redundant step of download & then attach we can have an option where we can copy the attachments directly to Email Client template from the record.

Consider an example of Incident where you have 5 documents attached & all of these 5 needs to be sent you can have an option of 'Include Attachments' from Notification but you may not want the attachments to sent always & thus is not the option you may opt for.

In that case you just get a Before Insert/Update Business rule on Email (sys_email) table with below snippet & its done.

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

    // Add your code here
    var lookforatt=new GlideRecord('sys_attachment');
    lookforatt.addQuery('table_sys_id',current.instance);
    lookforatt.query();
    while(lookforatt.next())
        {
GlideSysAttachment.copy('incident', current.instance, 'sys_email', current.sys_id);
}
})(current, previous);

What the above code does is just copies all the attachment from source (incident) in above case to Email Client. Something like below.

For instance a record has 3 attachments.

image

When Email Client Template is opened all attachments are copied.

image

GlideSysAttachment.copy('incident', current.instance, 'sys_email', current.sys_id);

where 'incident' is source table & can be replaced with required table for copying the attachment from record to Email Client template.

Thanks,

Jaspal Singh

View original source

https://www.servicenow.com/community/itsm-articles/copy-attachments-to-email-client-template/ta-p/2304626