Generate a PDF from a document template (HTML)

Justin Lucas
Kilo Sage

Hi all,

I'm trying to generate an HR document template from a UI action using the instructions on the documentation site. The documentation states that a UI action can be used to generate the PDF. However, I can't find any real examples of where this is being used so I don't know exactly how to format the code in the UI action (or what other steps may be involved to make this work, other than creating the template itself). The Generate a PDF from a document template (HTML) page gives some code examples but I can't seem to make it work.

Can someone please provide an example and any additional details on how I can get this to work?

Thanks,

Justin

EDIT: To give some more context, I'm trying to generate the PDF on an HR task using data from the parent HR case.

1 ACCEPTED SOLUTION

Hi Michael,

Thank you for your response. I ended up making it that far but was still seeing an error for "PDF template cannot be found". I did some debugging and found that I wasn't sending over the right parameters to pull in the PDF template. After fixing the code, it works now.

Here is what I ended up using in the UI action:

var tableName = current.parent.sys_class_name;
var tableId = current.parent.sys_id;
var targetTableName = current.getTableName();
var targetTableId = current.getUniqueValue();

var hrForm = new GeneralHRForm(tableName, tableId, targetTableName, targetTableId).generate();

So a combination of the code above and ensuring the PDF template was on the case resolved the issue.

Appreciate your help!

Justin

View solution in original post

3 REPLIES 3

michaelj_sherid
ServiceNow Employee
ServiceNow Employee

Hi Justin,

 

You can call to that template from the HR Case template (there is a PDF Template field you can add to the HR Case Template). You can have the OOB generate the document automatically using the case option on the HR Service Config, or you can manually generate it from the button on the case (once it is in Work In Progress).

 

find_real_file.png

Hi Michael,

Thank you for your response. I ended up making it that far but was still seeing an error for "PDF template cannot be found". I did some debugging and found that I wasn't sending over the right parameters to pull in the PDF template. After fixing the code, it works now.

Here is what I ended up using in the UI action:

var tableName = current.parent.sys_class_name;
var tableId = current.parent.sys_id;
var targetTableName = current.getTableName();
var targetTableId = current.getUniqueValue();

var hrForm = new GeneralHRForm(tableName, tableId, targetTableName, targetTableId).generate();

So a combination of the code above and ensuring the PDF template was on the case resolved the issue.

Appreciate your help!

Justin

Hi Justin,

We are having similar requirement to generate PDF from HTML template.

Would you please share how the code above works?

Thank you.

Godfrey