logo

NJP

Generating and Attaching Document Templates in ServiceNow to Record - Server Side

New article articles in ServiceNow Community · Jan 23, 2025 · article

Often, we need to configure a document template for a table and generate a PDF file to attach to the target record using server-side scripting.

Here's how you can generate and attach the document template file to the target record. This works in both global & scoped app.

//recordId - Sys ID of the target record. This record must be from the table defined in the document template. //documentTemplateId - Sys ID of the document template to use for pdf generation. //pdfName - Name of the pdf file var recordId = 'a9a16740c61122760004fe9095b7ddca'; var documentTemplateId = '50e6c385db175e10727ee7dcd39619f2'; var pdfName = 'INC_Template.pdf'; new sn_doc.GenerateDocumentAPI().generateDocumentForTask(recordId, documentTemplateId, pdfName);

Output:

generate document using document template from server side script.gif

View original source

https://www.servicenow.com/community/service-operations-workspace/generating-and-attaching-document-templates-in-servicenow-to/ta-p/3157650