HR module : Generate document to attach to record HR Case, using a template
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
Hi, I want to generate a document from a template and attach it to the hr case with flow designer. I've used the oob action but it didn't work, so I've made a custom action. At least I've put the sys id of the template but also it didn't work:
(function execute(inputs, outputs) {
var caseId = inputs.hr_case && inputs.hr_case.sys_id;
if (!caseId) {
outputs.success = false;
outputs.message = 'Missing hr_case';
return;
}
var HTML_TEMPLATE_ID = 'b2842479c337fa9071a31bbc7a013138';
var pdfName = 'PDF TEST.pdf';
try {
// --- 1. Recupero template
var tpl = new GlideRecord('sn_doc_html_template');
if (!tpl.get(HTML_TEMPLATE_ID)) {
outputs.success = false;
outputs.message = 'HTML Template not found';
return;
}
// --- 2. HRSD
var gen = new sn_hr_core.DocumentTemplateGeneration();
// --- 3. Generazione PDF HR CASE + allegato
var result = gen.generateFromTemplate(caseId, HTML_TEMPLATE_ID, pdfName);
if (!result || !result.attachment_id) {
outputs.success = false;
outputs.message = 'DocumentTemplateGeneration returned null';
return;
}
outputs.success = true;
outputs.attachment_sys_id = result.attachment_id;
outputs.file_name_out = pdfName;
outputs.message = 'Success';
} catch (e) {
outputs.success = false;
outputs.message = 'Error: ' + e;
}
})(inputs, outputs);
It seems that it didn't find the template, could you help me?
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Check this blog/post. Hope it will help you.
KB0727178: How to apply a template when we create an HR Case or Change in Flow Designer
