HR module : Generate document to attach to record HR Case, using a template

Alessia Russo
Tera Expert

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?


Click to expand Click to expand HRSD category Click to collapse HRSD category

1 REPLY 1

Tanushree Maiti
Tera Sage

Hi @Alessia Russo 

 

Check this blog/post. Hope it will help you.

 

https://www.servicenow.com/community/hrsd-articles/generate-multiple-documents-on-a-case-simple-flow...

 

KB0727178: How to apply a template when we create an HR Case or Change in Flow Designer 

 

https://www.servicenow.com/community/hrsd-forum/generate-document-and-attach-it-to-hr-case/m-p/32494....

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: