The CreatorCon Call for Content is officially open! Get started here.

How to use Document Template on incident table.

sakshinitna
Tera Contributor

Document Template- - In ServiceNow, a Document Template is a reusable content layout that allows users to quickly generate standardised documents with pre-filled data from records or to attach any pdf required accordingly.

 

 

Step 1: Create a Document Template
All > Document Templates > All Document Templates > New

You’ll be prompted to select the type of document template you want to create:

HTML Template

An HTML Template creates documents that you can view right inside ServiceNow.
It’s great for things like emails or on-screen reports because it supports full HTML and CSS styling, so you can design it however you like.
The document stays editable and dynamic, which means you can tweak it or update it anytime.

 

PDF Template

A PDF Template turns that same layout into a fixed, downloadable document — perfect for things like incident reports, receipts, or official records.
Once generated, it’s locked and read-only, so no one can change it.
Think of it as the “final version” of your document, ready to print or share.

 

*First create one custom reference field on incident table called Document template referencing to document template table.*

 

 

Step 2 : Create the Script Include

You have three scripts here:

  1. IncidentAPI
  2. Incident API Imp l
  3. IncidentDocumentClientUtil

   

 

1.IncidentAPI

sakshinitna_1-1760354585475.png

 

This script extends the functionality from another class (Incident API Imp l).

It serves as the public API class that other scripts or UI policies can call.

It doesn’t contain logic itself — it just acts as a bridge or interface that points to the implementation class.

 

 

2.Incident API Imp l

sakshinitna_2-1760354672515.png

 

This script contains the actual business logic for incident-related operations.

The method showGenerateDocument() decides whether to show or hide the "Generate Document" button.

It checks the incident state — for example, only shows the button if the state is Resolved (6) or Closed (7).

 

 

3.IncidentDocumentClientUtil

sakshinitna_3-1760354721506.png

 

This Script Include is client-callable (AbstractAjaxProcessor) — it can be invoked from a UI Action using GlideAjax.

It receives input parameters from the client (like selected template, incident number, and Sys ID).

It uses s n_doc.GenerateDocumentAPI() to generate a document (PDF/HTML) based on the chosen template and attaches it to the record.

Finally, it returns a success/failure message back to the client script

 

 

 

Step 3 : Add a “Generate Document” UI Action

  • Name: Generate Document
  • Table: Incident
  • Action name: generate_document
  • Form button: Checked
  • Condition: Leave blank (or use your display logic later)
  • On click: generateDocument()

sakshinitna_5-1760354995556.png

 

 

 

Step 4: Testing

Go to the Incident table and open any incident record.

If the state is set to Closed or Resolved, you should see the “Generate Document” button.

Select a template from the custom field you added, then click the button — a PDF document will be created and automatically attached to the incident record.

sakshinitna_4-1760354780438.png

 

 

 

 

 

 

 

 

 

0 REPLIES 0