logo

NJP

Using ServiceNow's Document Templates to power your business apps

Import · Oct 12, 2022 · article

ServiceNow uses Document Templates heavily in HRSD and BCM Applications. Document templates solves following broad use cases:

  1. Setup of Templates to allow specific branding, formatting and other rich content aspects.
  2. Allow PDF extraction from ServiceNow using the template (which can include specific ticket/case fields)
  3. Allow participants / approvers to review & sign the document

A good detail of the these use cases are listed in Docs.

But still there is very limited detail on how to set this up for a new business app that you'd like to develop and consume.

In this article, I will discuss on how you can leverage Document Templates for your custom apps.

Assumption: I am assuming that you have a global scope app (example ITSM apps) or already have a custom service management app which will leverage Document Templates.

Step 1: HTML Template setup:

  1. Setup your template. Go to Document Templates > All Document Templates > New
  2. For this example we will use HTML Templates (i.e. Type = HTML Template).
  3. Fill the details (name, category, body).
    1. If category is not available, create a new category. Ensure to choose a name which is self-explanatory about the purpose it will solve.

Screenshot 2022-10-12 at 9.39.46 AM.png

a. In the body, if you realize formatting is not okay, use source code option and you can now use HTML tags to work your way through.

source code option.png

b. You can use "Insert Table of Contents" to add table of contents. When working with ToC (Table of Contents), make use of various Heading styles like

,

tags to allow ToC to be built later. Usage of CSS is not supported currently.

Screenshot 2022-10-12 at 9.47.51 AM.png

More details at docs.

c. Setup Header and Footer for the template.

d. I did not have any signature requirement. But if you have, then you can use the Participants section.

Step 2: Logic to pick Template in the case form:

  1. Either add a field in the case form for the template and logic to pick the template automatically just like in HRSD application, or
  2. You can define a system property if it is just one template that will be used.

Step 3: Understanding the OOTB objects to be used and setting our objects. Below is a rough package flow diagram to explain the logic and requirement for the different objects:

Flow logic.png

UI button ("Preview document") is in the custom scope

Screenshot 2022-10-12 at 11.48.15 AM.png

and the jumper script (global.documentGenerator) is in the global scope (accessible from all scopes) which allows us to talk to Document Template scoped script includes.

When you run it for the first time, you will get errors for Caller Restricted Access. You'd have to approve those and in future, you will not receive the error.

Going back to the case form where your UI button is placed, clicking it now will attach the PDF document to your case ticket.

Screenshot 2022-10-12 at 11.48.27 AM.png

Thanks for reading!! Please share your feedback in the comments.

View original source

https://www.servicenow.com/community/architect-articles/using-servicenow-s-document-templates-to-power-your-business/ta-p/2348548