How to Generate and Embed a QR Code in a Document Template in ServiceNow
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2025 03:44 AM
📎 How to Generate and Embed a QR Code in a Document Template in ServiceNow
This article explains how to dynamically generate a QR Code in ServiceNow and embed it into a Document Template using a Document Template Script. This is useful for adding QR codes to PDF or Word documents such as tickets, receipts, confirmations, or forms.
🔹 Step 1: Import and Commit the Update Set
- attached file
✅ This update set includes the qrGeneration template script using global.HtmlRenderQRCode().
🔹 Step 2: Insert the QR Code Placeholder in Your Document
- Navigate to All → Document Template → Document Template.
- Open the required document template record.
- In the Template Body field, insert the following placeholder where the QR Code should appear:
${template_script:qrGeneration}
🔹 Step 3: Create the Document Template Script
Navigate to All → Document Template → Document Template Scripts and click New. Use the following script:
(function runTemplateScript(target /*GlideRecord for target task*/, docTemplate /*GlideRecord for doc template*/) { var url = gs.getProperty('glide.servlet.uri') + "?id=ticket&sys_id=" + target.sys_id;
var htmlRender = global.HtmlRenderQRCode(url);
return htmlRender;
})(target, docTemplate);
- Name: qrGeneration
- Applies to: Set the relevant table (e.g., Case, Task)
📝 Ensure the glide.servlet.uri system property exists. If not, hardcode the URL for testing.
🔹 Step 4: Test the Document Generation
- Navigate to All → Document Template → Document Template.
- Open your configured document template.
- Click the Preview button.
- Select a specific record (e.g., case or task).
- Click Generate.
✅ The generated document should now display the QR Code in the placeholder's location.
📌 Summary
Step Action
1 | Import the update set and commit it |
2 | Insert ${template_script:qrGeneration} in the document template |
3 | Create the Document Template Script using HtmlRenderQRCode() |
4 | Use the Preview button and test with a specific record |
- 637 Views
0 REPLIES 0