Skip to content

Commit 35372f3

Browse files
Generate Pdf letter in HR case by Fulfiller. If no pdf letter attached in HR case it will create pdf letter. (#2244)
* README.md * pdfletter.js * Delete Server-Side Components/Business Rules/PdfletterGeneration directory * README.md * letter.js
1 parent a4bda17 commit 35372f3

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#Contribution
2+
3+
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.
4+
5+
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).
6+
Document Template -> All Document Templates - > New
7+
As per the script, the PDF letter is generated and named using the HR case subject's name — for example:
8+
"Letter: " + empName + ".pdf".
9+
10+
Functionality -
11+
When a fulfiller changes the case state to "Work in Progress", the PDF letter is automatically generated and attached to the HR case record.
12+
13+
Business Rule Description -
14+
15+
Name - pdf Letter generation
16+
Table - sn_hr_core_case
17+
Condition - state is "work in Progress"
18+
Update - Check the box
19+
When -select after
20+
21+
This BR will prevent the duplicate letter generation for multiple updates in work in Progress state.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
(function executeRule(current, previous /*null when async*/ ) {
3+
4+
// Add your code here
5+
var recordId = current.sys_id.toString();
6+
var empName = current.subject_person;
7+
8+
var templateId1 = gs.getProperty("sn_hr_core.letter"); // Document Template sysid
9+
10+
11+
var pdfFileName1 = 'Letter:' +empName+ '.pdf'; //letter name
12+
13+
14+
gs.info('[PDF Generation] HRC Number ' + recordId);
15+
16+
try {
17+
18+
var attachmentGR = new GlideRecord('sys_attachment'); //if any pdf letter attached
19+
attachmentGR.addQuery('table_name', 'sn_hr_core_case');
20+
attachmentGR.addQuery('table_sys_id', recordId);
21+
attachmentGR.addQuery('file_name', pdfFileName1);
22+
attachmentGR.query();
23+
24+
if (!attachmentGR.hasNext()) { //check for new letter
25+
var docGen1 = new sn_doc.GenerateDocumentAPI();
26+
docGen1.generateDocumentForTask(recordId, templateId1, pdfFileName1); // genereate pdf letter
27+
28+
gs.info('[PDF Generation] PDF attached to HRC: ' + recordId);
29+
}
30+
}
31+
32+
33+
catch (ex) {
34+
gs.error('[PDF Generation] Failed: ' + ex.message);
35+
}
36+
current.setWorkflow(false);
37+
}
38+
39+
40+
41+
})(current, previous);

0 commit comments

Comments
 (0)