ER Summary Report - Document Template
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
I am making some updates to the OOB ER Summary report document template and would like to include a section that lists the names of any attachments on the case. Has anyone found an easy way to do this? Would a Doc Template script be the best option?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
27m ago
Hi @ErinF ,
Yes, a Document Template script is a good approach for this. You can use a template script to query the attachments on the ER case and dynamically insert their file names into the generated report.
Here's how you can approach it:
1. In your ER Summary Report document template, add a placeholder section where you want the attachment names to appear.
2. Create a Document Template Script that queries the sys_attachment table for records associated with your ER case. You can use something like:
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_name', 'sn_hr_er_case');
gr.addQuery('table_sys_id', current.sys_id);
gr.query();
var attachments = [];
while (gr.next()) {
attachments.push(gr.getValue('file_name'));
}
template.put('attachment_list', attachments.join('\n'));
3. Then reference the variable in your document template (e.g., ${attachment_list}) to render the list of attachment file names.
A few things to keep in mind:
- Make sure the script runs in the context of the ER case record so that "current" refers to the correct case.
- If you also want to include attachments from related records (e.g., tasks or interactions linked to the case), you'll need to extend the query accordingly.
- Test with the Document Template preview to confirm the attachment names render correctly before publishing the updated template.
Hope this helps!
