- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2025 11:42 PM
Could you please help me with generating a Word document in ServiceNow? I am looking for a solution similar to how PDF documents are generated. Has anyone implemented Word document generation for any record in ServiceNow? If so, I would appreciate guidance on how to configure it.
I want to create a UI Action in Workspace where a user can select a record and click a button to generate a Word document. We can generate PDFs, but I am not sure how to do the same for Word documents. Could you please provide the steps or a working solution?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2025 12:16 AM
Hi @KanishkaS814962 ,
You can achieve this requirement by implementing a UI Action. Specifically, you will need to configure a client-side UI Action together with a client-callable Script Include. Both components work in coordination to generate the Word document. The implementation details and code samples are provided below:
Here is the UI Action script:-
var BGHDownloadUtils = Class.create();
BGHDownloadUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
downloadDoc: function() {
var ids = this.getParameter('sysparm_ids');
if (!ids)
return "";
var idList = ids.split(',');
// This will hold the combined HTML
var mergedHTML = "";
// Loop through each selected record
for (var i = 0; i < idList.length; i++) {
var rec = new GlideRecord('incident'); // Change table if required
if (!rec.get(idList[i]))
continue;
// Build HTML content manually (NO TEMPLATE USED)
var html = "";
html += "<h2>Incident Details</h2>";
html += "<p><b>Number:</b> " + rec.getValue("number") + "</p>";
html += "<p><b>Short Description:</b> " + rec.getValue("short_description") + "</p>";
html += "<p><b>Description:</b> " + rec.getValue("description") + "</p>";
html += "<p><b>Priority:</b> " + rec.getDisplayValue("priority") + "</p>";
html += "<br><hr><br>";
mergedHTML += html;
}
if (!mergedHTML)
return "";
// File name
var fileName = "Selected_Records.doc";
// Dummy record to attach the document
var dummy = new GlideRecord("sys_script");
dummy.initialize();
dummy.name = "Download Holder";
var dummyID = dummy.insert();
// Attach the HTML as Word file
var sa = new GlideSysAttachment();
var attachmentID = sa.write(dummy, fileName, "application/msword", mergedHTML);
return attachmentID;
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2025 06:12 AM
do you want to generate and add from client side (UI) or server side?
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2025 10:07 PM
Hi @KanishkaS814962 ,
You can achieve this requirement by implementing a UI Action. Specifically, you will need to configure a client-side UI Action together with a client-callable Script Include. Both components work in coordination to generate the Word document. The implementation details and code samples are provided below:
Here is the UI Action script:-
var BGHDownloadUtils = Class.create();
BGHDownloadUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
downloadDoc: function() {
var ids = this.getParameter('sysparm_ids');
if (!ids)
return "";
var idList = ids.split(',');
// This will hold the combined HTML
var mergedHTML = "";
// Loop through each selected record
for (var i = 0; i < idList.length; i++) {
var rec = new GlideRecord('incident'); // Change table if required
if (!rec.get(idList[i]))
continue;
// Build HTML content manually (NO TEMPLATE USED)
var html = "";
html += "<h2>Incident Details</h2>";
html += "<p><b>Number:</b> " + rec.getValue("number") + "</p>";
html += "<p><b>Short Description:</b> " + rec.getValue("short_description") + "</p>";
html += "<p><b>Description:</b> " + rec.getValue("description") + "</p>";
html += "<p><b>Priority:</b> " + rec.getDisplayValue("priority") + "</p>";
html += "<br><hr><br>";
mergedHTML += html;
}
if (!mergedHTML)
return "";
// File name
var fileName = "Selected_Records.doc";
// Dummy record to attach the document
var dummy = new GlideRecord("sys_script");
dummy.initialize();
dummy.name = "Download Holder";
var dummyID = dummy.insert();
// Attach the HTML as Word file
var sa = new GlideSysAttachment();
var attachmentID = sa.write(dummy, fileName, "application/msword", mergedHTML);
return attachmentID;
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2025 12:16 AM
Hi @KanishkaS814962 ,
You can achieve this requirement by implementing a UI Action. Specifically, you will need to configure a client-side UI Action together with a client-callable Script Include. Both components work in coordination to generate the Word document. The implementation details and code samples are provided below:
Here is the UI Action script:-
var BGHDownloadUtils = Class.create();
BGHDownloadUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
downloadDoc: function() {
var ids = this.getParameter('sysparm_ids');
if (!ids)
return "";
var idList = ids.split(',');
// This will hold the combined HTML
var mergedHTML = "";
// Loop through each selected record
for (var i = 0; i < idList.length; i++) {
var rec = new GlideRecord('incident'); // Change table if required
if (!rec.get(idList[i]))
continue;
// Build HTML content manually (NO TEMPLATE USED)
var html = "";
html += "<h2>Incident Details</h2>";
html += "<p><b>Number:</b> " + rec.getValue("number") + "</p>";
html += "<p><b>Short Description:</b> " + rec.getValue("short_description") + "</p>";
html += "<p><b>Description:</b> " + rec.getValue("description") + "</p>";
html += "<p><b>Priority:</b> " + rec.getDisplayValue("priority") + "</p>";
html += "<br><hr><br>";
mergedHTML += html;
}
if (!mergedHTML)
return "";
// File name
var fileName = "Selected_Records.doc";
// Dummy record to attach the document
var dummy = new GlideRecord("sys_script");
dummy.initialize();
dummy.name = "Download Holder";
var dummyID = dummy.insert();
// Attach the HTML as Word file
var sa = new GlideSysAttachment();
var attachmentID = sa.write(dummy, fileName, "application/msword", mergedHTML);
return attachmentID;
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
What’s implemented in the accepted solution is essentially HTML being exported as a Word file (.doc with application/msword). That can work as a workaround, but it’s not true Word document generation (.docx), so matching real Word templates with headers, footers, styling and layouts can become difficult.
In practice teams usually either generate PDFs using Document Templates, or use a document generation solution designed for Word templates when .docx output is required (for example apps from the ServiceNow Store like Office Templater).
The HTML approach can work for simple exports, but it tends to hit limitations once the document formatting becomes more complex.
