- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
10-11-2022 11:24 PM - edited 10-14-2022 06:25 AM
ServiceNow uses Document Templates heavily in HRSD and BCM Applications. Document templates solves following broad use cases:
- Setup of Templates to allow specific branding, formatting and other rich content aspects.
- Allow PDF extraction from ServiceNow using the template (which can include specific ticket/case fields)
- 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:
- Setup your template. Go to Document Templates > All Document Templates > New
- For this example we will use HTML Templates (i.e. Type = HTML Template).
- Fill the details (name, category, body).
- If category is not available, create a new category. Ensure to choose a name which is self-explanatory about the purpose it will solve.
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.
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.
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:
- Either add a field in the case form for the template and logic to pick the template automatically just like in HRSD application, or
- 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:
UI button ("Preview document") is in the custom scope
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.
Thanks for reading!! Please share your feedback in the comments.
- 10,820 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
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 */
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
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".
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
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.
I also tried changing the Scope, from mine to Global, but it doesn't work.
Can you help me?
Thank you in advance!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
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.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
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!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Does anybody knows does Document Templates requires any Subscription Extra
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@MateoBilandzija My understanding is that Document Templates is a platform capability and does not require additional licensing.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
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