UI Action to preview pdf using hr_PdfUtils does not work

davilu
Mega Sage

Hi experts, our team wants to create a UI Action button on a case table that allows a user to preview a filled out pdf before generating the pdf.  Two questions to this:  1) is this possible and more generally 2) how does the preview function work in the OOTB script include hr_PdfUtils?

 

In a PDI, I've created 2 buttons, one that will Generate a PDF and another to Preview PDF.  Both UI Action buttons call hr_PdfUtils.  For the Generate PDF UI Action, the code looks like this (we call the function prefillPDF from hr_PdfUtils) and it works great:

 

var wfa_caseID = '607e03320b30220097432da0d5673a23'
var pdfTemplateSysID = '73f2114b83001210027cad20ceaad3d8'; //sn_hr_core_pdf_template 
var draftDocSysID = new sn_hr_core.hr_PdfUtils().prefillPdf(pdfTemplateSysID, false, wfa_caseID, 'sn_hr_core_case_workforce_admin', wfa_caseID);

var grAttachment = new GlideRecord('sys_attachment');
grAttachment.get(draftDocSysID);
var copyDoc = new GlideSysAttachment.copy('pdf_draft', grAttachment.table_sys_id, 'sn_hr_core_case_workforce_admin', wfa_caseID);

action.setRedirectURL(current);

 

For the Preview PDF UI Action, we tried calling the function "preview" from hr_PdfUtils, but it doesn't do anything:

 

var wfa_caseID = '607e03320b30220097432da0d5673a23'
var pdfTemplateSysID = '73f2114b83001210027cad20ceaad3d8'; //sn_hr_core_pdf_template 
var draftDocSysID = new sn_hr_core.hr_PdfUtils().preview(pdfTemplateSysID);
action.setRedirectURL(current);

 

What does the "preview" function even do?  Does it bring up a preview modal window and display the document or does it do something completely different?

 

Is there a way for a user to click a UI Action to display a filled out pdf from the platform view?

2 REPLIES 2

HIROSHI SATOH
Mega Sage

The preview function is designed to open the generated PDF in a new window or tab. You can achieve the desired preview functionality by generating a PDF with the prefillPdf function and then opening that PDF with the preview function.

var wfa_caseID = '607e03320b30220097432da0d5673a23';
var pdfTemplateSysID = '73f2114b83001210027cad20ceaad3d8'; //sn_hr_core_pdf_template 

// Generate the PDF draft
var draftDocSysID = new sn_hr_core.hr_PdfUtils().prefillPdf(pdfTemplateSysID, false, wfa_caseID, 'sn_hr_core_case_workforce_admin', wfa_caseID);

// Retrieve the PDF attachment
var grAttachment = new GlideRecord('sys_attachment');
grAttachment.get(draftDocSysID);

// Preview the PDF
new sn_hr_core.hr_PdfUtils().preview(grAttachment.sys_id);

action.setRedirectURL(current);

 

Thanks @HIROSHI SATOH!  I gave that a try and it does generate the attachment in sys_attachment, but the preview still doesn't do anything.