Where to find Generate button script within the Preview Document UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2024 05:29 AM
Our team has requirements for end users to be able to preview and download a document (e.g. offer letter) from a HR Task. There is an OOTB UI Action on HR Case table called Preview Document that appears to do exactly that. One thing we've noticed is our client's production instance does not allow for the Preview Document Modal to render. From what we understand this is a security setting that we cannot control. As a work around, we really just want to give them the ability to download the document instead -- which is what the Generate button does inside of the Preview Document modal:
Our team has looked through the Preview Document UI Action script, but can't seem to figure out where the code for the Generate button lives:
function previewDocument(){
var sysId = typeof rowSysId == 'undefined' || rowSysId == null ?
g_form.getUniqueValue() : rowSysId;
if (g_form.getValue('pdf_template') == '') {
g_form.addErrorMessage(getMessage('PDF Template is required'));
return;
}
if(g_form.getValue('hr_service') == ''){
g_form.addErrorMessage(getMessage('HR Service is required'));
return;
}
var dialogClass = GlideModal ? GlideModal : GlideDialogWindow;
var dialog = new dialogClass('Preview document dialog');
dialog.setTitle(getMessage('Preview Document'));
dialog.setPreference('sysparm_sysId', sysId);
dialog.setPreference('sysparm_tableName', g_form.getTableName());
dialog.setPreference('sysparm_targetTable', g_form.getTableName());
dialog.setPreference('sysparm_targetId', sysId);
dialog.setPreference('sysparm_scriptName', 'global.HRSecurityUtilsAjax');
dialog.setPreference('sysparm_hrService', g_form.getValue('hr_service'));
dialog.setPreference('sysparm_edit', 'false');
dialog.setPreference('sysparm_sign', 'false');
dialog.setPreference('sysparm_generate_document', 'true');
dialog.setPreference('sysparm_pdfTemplateTableName','sn_hr_core_pdf_template');
dialog.render();
}
Does anyone know where we can find the code for the embedded Generate button?
We want to create a new UI Action that essentially takes that code from the Generate button onto the HR Case, so users can click on it and have their document generate and download automatically. Thanks for any help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 04:32 AM
Hi @davilu ,
The dialogClass is a UI Page, which contains the logic.
It seems the UI Page checks if it is a PDF template and if yes calls the "HRSecurityUtilsAjax" script include with the function "ajaxFunction_getPdfDraftDocument"
ajaxFunction_getPdfDraftDocument : function() {
var taskId = this.getParameter('sysparm_task_sysid');
var pdfDraftDocumentId = new sn_hr_core.hr_PdfUtils().getPdfDraftDocument(taskId);
return new global.JSON().encode({attachmentId:pdfDraftDocumentId});
}
Where the pdfDraftDocumentId looks to be a sysId from the sys_attachment table.
Hope this helps,
Hayo