Export to pdf in the HR case should export fields with value

Community Alums
Not applicable

Hi,

 

I need to create a Ui action to print the HR case only if the field has a value, fields with empty or no value is not required while clicking on "Print" ui action. Can anyone help me on this.

 

 

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@Community Alums You can use a UI Action to prepare HTML from the fields which have data on them and use the PDFGenerationAPI (https://developer.servicenow.com/dev.do#!/reference/api/rome/server/sn_pdfgeneratorutils-namespace/PDFGenerationAPIBothAPI) to generate the PDF from it. Here the example quoted at the shared URL.

 

var v = new sn_pdfgeneratorutils.PDFGenerationAPI;

//  (Option) get HTML from the description field of an incident record
var gr = new GlideRecord("incident");
var html;

if (gr.get("<tableSysId>")) {
 html = gr.description.toString();
}

var result = v.convertToPDF(html, "incident", "<target_sys_id>", "myPDF");
gs.info(JSON.stringify(result));

Hope this helps.

Community Alums
Not applicable

Hi @Community Alums ,

This is the Out of Box, designed behavior as only fields on the form and their values are carried over to the PDF.

 

Community Alums
Not applicable

Hi @Community Alums , I had few fields which are hided on the case form through client script and ui policy and they don't have any field value but when exported to pdf those were also getting exported so I need to export to pdf only the fields which has value

Community Alums
Not applicable

Hi @Community Alums ,

Unfortunately, even those fields would get exported with blank values.