diff --git a/Server-Side Components/Business Rules/Pdf Letter create/README.md b/Server-Side Components/Business Rules/Pdf Letter create/README.md new file mode 100644 index 0000000000..42a0210b1a --- /dev/null +++ b/Server-Side Components/Business Rules/Pdf Letter create/README.md @@ -0,0 +1,21 @@ +#Contribution + +The Business Rule is triggered after an update on the (HR case)"sn_hr_core_case" table, specifically when the case state is set to "Work in Progress". This rule generates a PDF letter based on the trigerred conditions. + +Document Template created seperately. Document Template Name - PDF Letter Employee.The Document Template Sys ID is passed within the script, and the corresponding document template has been created separately (refer to the attached screenshot for reference). +Document Template -> All Document Templates - > New +As per the script, the PDF letter is generated and named using the HR case subject's name — for example: +"Letter: " + empName + ".pdf". + +Functionality - +When a fulfiller changes the case state to "Work in Progress", the PDF letter is automatically generated and attached to the HR case record. + +Business Rule Description - + +Name - pdf Letter generation +Table - sn_hr_core_case +Condition - state is "work in Progress" +Update - Check the box +When -select after + +This BR will prevent the duplicate letter generation for multiple updates in work in Progress state. diff --git a/Server-Side Components/Business Rules/Pdf Letter create/letter.js b/Server-Side Components/Business Rules/Pdf Letter create/letter.js new file mode 100644 index 0000000000..a2969a1d10 --- /dev/null +++ b/Server-Side Components/Business Rules/Pdf Letter create/letter.js @@ -0,0 +1,41 @@ + +(function executeRule(current, previous /*null when async*/ ) { + + // Add your code here + var recordId = current.sys_id.toString(); + var empName = current.subject_person; + + var templateId1 = gs.getProperty("sn_hr_core.letter"); // Document Template sysid + + + var pdfFileName1 = 'Letter:' +empName+ '.pdf'; //letter name + + + gs.info('[PDF Generation] HRC Number ' + recordId); + + try { + + var attachmentGR = new GlideRecord('sys_attachment'); //if any pdf letter attached + attachmentGR.addQuery('table_name', 'sn_hr_core_case'); + attachmentGR.addQuery('table_sys_id', recordId); + attachmentGR.addQuery('file_name', pdfFileName1); + attachmentGR.query(); + + if (!attachmentGR.hasNext()) { //check for new letter + var docGen1 = new sn_doc.GenerateDocumentAPI(); + docGen1.generateDocumentForTask(recordId, templateId1, pdfFileName1); // genereate pdf letter + + gs.info('[PDF Generation] PDF attached to HRC: ' + recordId); + } + } + + + catch (ex) { + gs.error('[PDF Generation] Failed: ' + ex.message); + } + current.setWorkflow(false); +} + + + +})(current, previous);