Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Server-Side Components/Business Rules/Pdf Letter create/README.md
Original file line number Diff line number Diff line change
@@ -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.
41 changes: 41 additions & 0 deletions Server-Side Components/Business Rules/Pdf Letter create/letter.js
Original file line number Diff line number Diff line change
@@ -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);
Loading