Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

I want to use the pdf document template to create a pdf where i want to pass the fields dynamically

kaustubhdub
Tera Contributor

I’m using GenerateDocumentAPI to create a PDF from a document template. The API requires a recordId from the template’s table (for example, a Case record) to map and fill merge fields.
My use case is different: I already have the values (from an integration) and don’t have or don’t want to use the Case record. Is there a way to pass a set of field/value pairs directly to the template and generate the PDF without providing a case record ID? If not, what’s the recommended approach?

Regards
Kaustubh Dubey

2 REPLIES 2

gracemiller84
Giga Contributor

The GenerateDocumentAPI in ServiceNow is designed to merge data from an existing record, so it requires a recordId to map fields. If you don’t have a record, the typical workaround is to create a temporary record in the relevant table, populate it with your field/value pairs, generate the PDF using that record, and then optionally delete the temporary record. This allows you to leverage the template without modifying its design while still providing dynamic data. There’s no built-in way to pass arbitrary field/value pairs directly without a record.

ben_hollifield
Tera Guru

Hi @kaustubhdub , 

 

If you need a solution with a great deal of flexibility around PDF generation & data sources, Yansa Labs' PDF Generator offers quite a lot. It's a certified app on the ServiceNow Store. You can check the links below for more information. Feel free to reach out to Yansa Labs directly with any questions!