diff --git a/Server-Side Components/Business Rules/Generate pdf/README.md b/Server-Side Components/Business Rules/Generate pdf/README.md new file mode 100644 index 0000000000..22cf69fff0 --- /dev/null +++ b/Server-Side Components/Business Rules/Generate pdf/README.md @@ -0,0 +1,19 @@ +#Contribution + +The Business Rule is triggered after an update on the 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 diff --git a/Server-Side Components/Business Rules/Generate pdf/letterPdf.js b/Server-Side Components/Business Rules/Generate pdf/letterPdf.js new file mode 100644 index 0000000000..7b80a2ff3e --- /dev/null +++ b/Server-Side Components/Business Rules/Generate pdf/letterPdf.js @@ -0,0 +1,32 @@ +(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 docGen1 = new sn_doc.GenerateDocumentAPI(); + docGen1.generateDocumentForTask(recordId, templateId1, pdfFileName1); + + gs.info('[PDF Generation] PDF attached to HRC: ' + recordId); + } + + + + catch (ex) { + gs.error('[PDF Generation] Failed: ' + ex.message); + } + current.setWorkflow(false); + + + +})(current, previous); diff --git a/Server-Side Components/Business Rules/PdfletterGeneration/README.md b/Server-Side Components/Business Rules/PdfletterGeneration/README.md new file mode 100644 index 0000000000..6ba5d77aa5 --- /dev/null +++ b/Server-Side Components/Business Rules/PdfletterGeneration/README.md @@ -0,0 +1,22 @@ +#Contribution + +The Business Rule is triggered after an update on the 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 + + + diff --git a/Server-Side Components/Business Rules/PdfletterGeneration/pdfletter.js b/Server-Side Components/Business Rules/PdfletterGeneration/pdfletter.js new file mode 100644 index 0000000000..7b80a2ff3e --- /dev/null +++ b/Server-Side Components/Business Rules/PdfletterGeneration/pdfletter.js @@ -0,0 +1,32 @@ +(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 docGen1 = new sn_doc.GenerateDocumentAPI(); + docGen1.generateDocumentForTask(recordId, templateId1, pdfFileName1); + + gs.info('[PDF Generation] PDF attached to HRC: ' + recordId); + } + + + + catch (ex) { + gs.error('[PDF Generation] Failed: ' + ex.message); + } + current.setWorkflow(false); + + + +})(current, previous);