Issue attaching file to Email Client Template from HR Agent Workspace

cbsden
Tera Expert

I need to pull in the attachments from 2 separate managed documents records when I apply an 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);

1 REPLY 1

Tanushree Maiti
Tera Patron

Hi @cbsden 

 

Check this: Attach a document from Managed Documents to an email 

Add Attachments to the Email Client Template automatically

Copy attachments to Email Client Template (...)

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti