Join us Dec. 16 for The Community Hour, our first global virtual User Group event!

Issue attaching files to an Email Client Template from case in HR Agent Worksapce

cbsden
Tera Expert

I need to pull in the attachments from 2 separate managed documents records when I apply and Email Client Template from the HR Agent workspace on an Employee Relations case. Template is applied, but the attachments are not being attached to the email draft.

 

I have the Email Client Template name set up as "Medical Documentation Cover Letter"

I have the Managed documents records set with names of " ER Accommodation Provider Request Medical Info" and "ER Accommodation 2026 ROI"

I have a business rule executing on the "sys_email_draft_ table; when to run = After Insert; and the following script:

 

(function executeRule(current, previous) {

 

    // TEMPLATE CHECK

    var templateName = (current.getDisplayValue('template') + '').toLowerCase().trim();

 

    if (templateName != 'medical documentation cover letter') {

        return;

    }

 

    // DOCUMENT NAMES

    var documentNames = [

        'ER Accommodation Provider Request Medical Info',

        'ER Accommodation 2026 ROI'

    ];

 

    for (var i = 0; i < documentNames.length; i++) {

 

        var docRevGr = new GlideRecord('dms_document_revision');

 

        docRevGr.addQuery('document.name', documentNames[i]);

        docRevGr.addQuery('active', true);

        docRevGr.orderByDesc('sys_created_on');

        docRevGr.setLimit(1);

        docRevGr.query();

 

        if (!docRevGr.next()) {

            gs.warn('No revision found for: ' + documentNames[i]);

            continue;

        }

 

        // COPY ATTACHMENTS

        GlideSysAttachment.copy(

            'dms_document_revision',

            docRevGr.getUniqueValue(),

            current.getTableName(),

            current.getUniqueValue()

        );

    }

 

})(current, previous);

2 REPLIES 2

Neither of those links really gave me what I was looking for. Can you help me with the script to copy the attachments from Managed Documents records into the email client template that I am applying from the HR Agent Workspace?