Sameer K Pandey
ServiceNow Employee
ServiceNow Employee
 

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 <h1>, <h2> 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.

Comments
Sohail Khilji
Kilo Patron
Kilo Patron

@Sameer K Pandey ,

 

Can you please also attach the screenshot of previewed Doc UI action ?

Sameer K Pandey
ServiceNow Employee
ServiceNow Employee

Hello @Sohail Khilji , here you go!!

 

 

var fileName = current.number+".pdf"; /* You can add date/time to add better uniqueness */

var taskId = current.sys_id;  /* it is good idea to use child task and use it's sys_id. However this was a simple use case and hence the main task's sys_id */

var templateGR = 'reference to template's sysID, use a system property to avoid hard coding';

var answer;

 

answer = new global.documentGenerator().generate(taskId, templateGR, fileName);

action.setRedirectURL(current); /*return to the main task form */

Adi18
Tera Contributor

Hi @Sameer K Pandey , 

Thanks for this solution. We're looking to implement something similar for our custom apps where the bsuiness need the ability to dynamically generate a contract document using some information stored in a custom request table. The template of the PDF will be predefined. The final generated document then needs to go through a series of users for review and to sign digitally.

 

We had previously explored this option of using Document Templates to attach a fillable PDF template, and used the GenerateDocument API to fill it based on information on a (custom)Task record. However, 

we’re still missing a piece of the puzzle where we can embed this document to our custom workflows and assign it to users for signing the PDF via tasks. We did add signature blocks and participants to the Document template, but not clear how to get the actual signatures from assignees on a task. I believe in HRSD that part is done via generation of "Document Tasks".

FeDa
Tera Contributor

Hi @Sameer K Pandey 

Thanks for this post.

I have a question: I want to create a document template in the application scope I am in, but when I try to select a table from those created for my application, these don't show up in the list.

FeDa_0-1681745071109.png

I also tried changing the Scope, from mine to Global, but it doesn't work.

Can you help me?

Thank you in advance!

Sameer K Pandey
ServiceNow Employee
ServiceNow Employee

Hello @FeDa,  Please see if your table is accessible from cross-scope. If not try to make it accessible either from:

a. Table's definition record (Application Access form section)

b. Application Cross Scope Access record (preferred) 

 

Let me know if any of these work for you.

Nagashree5
Tera Contributor

Hi @Sameer K Pandey ,

 

Thank you so much for the article. It was really helpful.

 

I have created the HTML template in sn_doc_html_template table on a custom RITM template. How can create the PDF from this every time a custom RITM for a specific form get's submitted. Can you please suggest. I have posted a question as well on this - Document Templates for RITM's - ServiceNow Community

Can we call this template from the workflow and generate the PDF? Please help!

Nagashree5
Tera Contributor

Hi @Adi18,

 

Did you get any solution for your question? My requirement is very similar to yours.

MateoBilandzija
Tera Expert

Does anybody knows does Document Templates requires any Subscription Extra

Calob G
Tera Contributor

@MateoBilandzija My understanding is that Document Templates is a platform capability and does not require additional licensing. 

Meenal Gharat
Giga Guru

Hi @Sameer K Pandey ,

 

My requirement is to convert the submitted RITM intoPDF which should include all the submitted values  and ask for Esignature from 3 levels for approvers.

Is this possible to achieve with this solution?

 

Can you show me the direction to configure the above .

Best Regards,

Meenal Gharat

Version history
Last update:
‎10-14-2022 06:25 AM
Updated by:
Contributors