{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":11284,"path":"employee-service-management/hr-service-delivery/doc-temp-gen.md","title":null,"bundle":null,"doc_type":null,"release":null,"body":"---\ntitle: Using Document Templates: Custom use case\ndescription: Understand how to use Document Templates outside of HR Service Delivery.\nlocale: en-US\ncanonical_url: https://www.servicenow.com/docs/r/australia/employee-service-management/hr-service-delivery/doc-temp-gen.html\nrelease: australia\nproduct: HR Service Delivery\nclassification: hr-service-delivery\ntopic_type: task\nlast_updated: \"2026-03-12\"\nreading_time_minutes: 1\nbreadcrumb: [Using Document Templates, Document Templates, HR Documents, HR Service Delivery, Employee Service Management]\n---\n\n# Using Document Templates: Custom use case\n\nUnderstand how to use Document Templates outside of HR Service Delivery.\n\n## Before you begin\n\nRole required: admin\n\n## Procedure\n\n1.  Define a document template for a given table, for example, Incident table.\n\n2.  To generate a PDF document from a document template, use the following API:\n\n    ```javascript\n    /**\n    * Description: Method to generate a PDF from a document template.\n    * @param {GlideRecord} recordId (GlideRecord of task table)\n    * @param {documentTemplateId} docTemplateId (sysId of document template)\n    * @param {String} pdfName name of generated pdf (Optional, if not passed then it will be taken from template name)\n    * @return {sysId} (sysId of the attachment)\n    */\n    new sn_doc.GenerateDocumentAPI().generateDocumentForTask(recordId, documentTemplateId, pdfName)\n    ```\n\n3.  If participants are configured for the document template, use the following API to initiate document tasks for participants:\n\n    ```javascript\n    /**\n    * Description: Method to prefill document with mapped values and attach it to record table.\n    * @param {GlideRecord} taskGr (GlideRecord of task table)\n    * @param {String} htmlBody html body of document (Optional, if not passed then it will be generated from template for html template)\n    * @param {SysId} docTemplateId (sysId of document template)\n    * @param {String} generatedPdfName name of generated pdf (Optional, if not passed then it will be taken from template name)\n    * @param {String} documentId (word template attachment sysId) (Only for word templates)\n    * @return {boolean} true/false\n    */\n    new sn_doc.GenerateDocumentAPI().initiateDocumentTasks(taskGr, htmlBody, docTemplateId, generatedPdfName, documentId)\n    \n    ```\n\n4.  To view the document tasks that are associated to a record:\n\n    1.  Open the record, for example, an incident record.\n    2.  Configure the related lists.\\[Omitted image \"config-rl.png\"\\] Alt text: Configure Related Lists on a record\n\n        A slushbucket opens. Add **Document Task -&gt; Parent** and **Save**.\\[Omitted image \"config-rl2.png\"\\] Alt text: Add document Tasks related list to an incident record\n\n        Document tasks associated to the record are displayed in **Document tasks** related list.\n\n        \\[Omitted image \"doc-tasks-rl.png\"\\] Alt text: Document tasks related list appears on the record form\n\n\n**Parent Topic:**[Using Document Templates](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/employee-service-management/hr-service-delivery/using-doc-templates.md)\n\n**Related topics**  \n\n\n[Using Document Templates: HR Service Delivery]()\n\n[Working on a document task]()\n\n[Using Guided Tours in Document Templates]()\n\n"}}