- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2024 10:26 AM - edited 05-06-2024 12:47 AM
Hi everyone,
After installing the Document Templates plugin, the file name of the generated pdf document no longer contains Subject Person name, but instead takes the name of the person who generated it.
Could you please share your solution if you have one?
Thank you in advance,
Victoria
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 10:56 AM
Hi @Community Alums ,
I faced similar issue. We can achieve this using customization.
Please create Before/insert BR in 'sys_attachment' table with global application scope.
(function executeRule(current, previous /*null when async*/ ) {
var case = new GlideRecord("sn_hr_core_case_global_mobility"); // put table name as per you configuration
case.addEncodedQuery('sys_id=' + current.table_sys_id);
case.query();
if (case.next()) {
var EmpName = case.subject_person.name;
}
current.file_name = 'Employee offer letter-' + EmpName;
// gs.info('EmpNameFilename' + current.file_name);
})(current, previous);
May be RCA record will be created post that please allowed RCA with target scope.
Please helpful & mark answer if it's really worthy for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 10:56 AM
Hi @Community Alums ,
I faced similar issue. We can achieve this using customization.
Please create Before/insert BR in 'sys_attachment' table with global application scope.
(function executeRule(current, previous /*null when async*/ ) {
var case = new GlideRecord("sn_hr_core_case_global_mobility"); // put table name as per you configuration
case.addEncodedQuery('sys_id=' + current.table_sys_id);
case.query();
if (case.next()) {
var EmpName = case.subject_person.name;
}
current.file_name = 'Employee offer letter-' + EmpName;
// gs.info('EmpNameFilename' + current.file_name);
})(current, previous);
May be RCA record will be created post that please allowed RCA with target scope.
Please helpful & mark answer if it's really worthy for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 02:00 AM
Hi @abirakundu23 , thank you for your reply. I just tested it and it solves my case.
Best regards,
Victoria
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Personally using Business Rules to rename attachments would be a messy and hard-to-maintain solution, especially across multiple case tables. It would require creating and managing separate rules just to rename files, which is not scalable. Instead, FINDING AND UPDATING the existing document generation logic is a cleaner and more maintainable approach. I traced the script that's causing the "logged in" user to appear in the generated PDF document:
UI Page: pdf_preview_document_dialog
↓
Button: Generate
↓
Script Include: HRDocumentTemplateAjax.generateDocumentForPdfTemplate(caseTable, caseId)
↓
Script Include: HRDocumentTemplateAjaxSNC.generateDocumentForPdfTemplate(caseTable, caseId)
↓
Script Include: HRDocumentTemplateUtils().generateDocumentForPdf(caseGr, caseId)
↓
Script Include: HRDocumentTemplateUtilsSNC().generateDocumentForPdf(caseGr, caseId)
↓
Function Call: HRDocumentTemplateUtilsSNC().getPdfName(documentTemplateId)
↓
THE CULPRIT IS THIS:
var documentTemplateId = caseGr.getValue('document_template');
getPdfName(documentTemplateId) {
var pdfName = docTemplateGr.name + "-" + <strong>gs.getUserDisplayName();</strong>
return pdfName;
}
To solve this, you need to edit the Script: HRDocumentTemplateUtils. You can't edit the HRDocumentTemplateUtilsSNC as it's a protected file.
You need to create a new method inside HRDocumentTemplateUtils to override what's in HRDocumentTemplateUtilsSNC. Full tested solution:
var HRDocumentTemplateUtils = Class.create();
HRDocumentTemplateUtils.prototype = Object.extendsObject(HRDocumentTemplateUtilsSNC, {
initialize: function() {
HRDocumentTemplateUtilsSNC.prototype.initialize.apply(this, arguments);
},
/*
Override the existing HRDocumentTemplateUtils.getPdfName(documentTemplateId) with the below. You need to add caseGr
*/
getPdfName: function (documentTemplateId, caseGr) {
var base = "";
var docTemplateGr = new GlideRecord("sn_doc_template");
if (docTemplateGr.get(documentTemplateId)) {
base = docTemplateGr.getValue("name");
}
var subjectPersonName = "";
try {
if (caseGr && caseGr.isValidRecord()) {
subjectPersonName = caseGr.getDisplayValue("subject_person");
}
} catch (ex) {
gs.error("HRDocumentTemplateUtils.getPdfName subject_person error: " + ex);
}
if (!gs.nil(subjectPersonName)) {
return base + "-" + subjectPersonName;
}
return base + "-" + gs.getUserDisplayName();
},
/*
You need to override too generateDocumentForPdf and generateDocumentForHtml as you need to change the way you call getPdfName.
*/
generateDocumentForPdf: function (caseGr, caseId) {
gs.info("Custom generateDocumentForPdf called from HRDocumentTemplateUtils");
// Delete already generated attachment
this._deleteGeneratedDocument(caseGr);
var documentTemplateId = caseGr.getValue('document_template');
var pdfName = this.getPdfName(documentTemplateId, caseGr);
var generatedDocumentId = new sn_doc.GenerateDocumentAPI().generateDocumentForTask(caseId, documentTemplateId, pdfName);
this._updateGeneratedDocumentFieldForCase(caseGr, generatedDocumentId);
return generatedDocumentId;
},
generateDocumentForHtml: function(htmlBody, caseGr) {
//Delete already generated document if exists.
this._deleteGeneratedDocument(caseGr);
var documentTemplateId = caseGr.getValue('document_template');
//Generate new document.
var pdfName = this.getPdfName(documentTemplateId, caseGr);
var htmlTemplateGr = new GlideRecord('sn_doc_html_template');
htmlTemplateGr.get(documentTemplateId);
var params = {};
params.htmlBody = htmlBody;
params.targetTable = caseGr.sys_class_name;
params.targetSysId = caseGr.sys_id;
params.generatedPdfName = pdfName;
params.htmlTemplateGr = htmlTemplateGr;
var generatedDocumentId = new sn_doc.HtmlTemplateUtils().generateDocumentAsAttachment(params);
// Update generated document field
this._updateGeneratedDocumentFieldForCase(caseGr, generatedDocumentId);
return generatedDocumentId;
},
type: 'HRDocumentTemplateUtils'
});
I hope this helps.
ArleneH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 09:45 AM
Hi @Community Alums ,
Did you get a chance to check my solution?
Please mark helpful & accept answer it's worthy for you.
