Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need Doc template script to display all attachment names in Summary report attached to single HRcase

KAura
Tera Contributor

Hi All,

 

I have a requirement to display all attached file names in ER Summary Report feature to a particular HR Case irrespective of which table it is attached to. For example - Corrective action, Involved partied, Child case, Er case or Allegation.

 

For this, i have written a document template script on 'sys_attachement' table and added it into 'Employee Relations Report' template but its just showing only attachments names those are attached to sn_hr_er_case but not from other related tables such as 'sn_hr_er_allegation' or 'sn_hr_er_corrective_actions'.

KAura_0-1704940281879.png

 

Document Template Script :-

--------------------------------------

(function runTemplateScript(target /*GlideRecord for target task*/ ) {

    var getHeaderCell = function(label) {
        return '<th style="border: 1px solid #dddddd; text-align: left; padding: 5px;font-family:times new roman; font-size: 12pt;">' + label + '</th>';
    };
    var getDataCell = function(value) {
        return '<td style="border: 1px solid #dddddd; text-align: left; padding: 5px;">' + value + '</td>';
    };
    var html = '';
    var attachmentGr = new GlideRecord('sys_attachment');
    attachmentGr.addEncodedQuery('table_name=sn_hr_er_case^file_nameNOT LIKEER Summary report.pdf^table_sys_id=' + target.getValue('sys_id'));
    //attachmentGr.addEncodedQuery('table_name=sn_hr_er_corrective_action^table_sys_id=' + target.getValue('sys_id'));
    //attachmentGr.addEncodedQuery('table_nameINsn_hr_er_case,sn_hr_er_involved_party,sn_hr_er_corrective_action,sn_hr_er_allegations^table_sys_id=' + target.getValue('sys_id'));
    attachmentGr.query();
    while (attachmentGr.next()) {
        html = html + '<tr>';
        html = html + getDataCell(attachmentGr.getDisplayValue('file_name'));
        html = html + getDataCell(attachmentGr.getDisplayValue('table_name'));
        html = html + getDataCell(attachmentGr.getDisplayValue('sys_updated_by'));
        html = html + '</tr>';
    }
    if (!gs.nil(html)) {
        var header = '<p class="summary-header"><span style="font-size: 12pt; font-family: times new roman;">Attachments</span></p>';
        html = header + '<div class="summary-details"><table style="width: 100%; overflow-wrap: anywhere; word-break: break-word; overflow: hidden; border-spacing: 0px 0;border-collapse: collapse; table-layout : fixed; margin-top: 11px;" align="center"><tr style="background-color: #e1e3e5;  color: #2e2e2e;">' + getHeaderCell('File Name') + getHeaderCell('Location') + getHeaderCell('Updated by') + html + '</table></div>'; //
    }
    return html;

})(target);
 
Summary report :- Showing just attachment which is attached to only sn_hr_er_case table
KAura_1-1704940740871.png

 

Can someone help me to update this script to get all the attachment names in same report.
1 REPLY 1

KAura
Tera Contributor

@Ankur Bawiskar @Chuck Tomasi  or @All MVP's - Can someone help here?