Generate MS Word from ServiceNow

Roderick De Guzman - 7th January 2013

Happy New Year everyone! As promised, here is another article relating to MS Word Document generation within the ServiceNow platform.

The Situation

Having been involved (and have successfully GONE LIVE!) in a Global HR Transformation programme utilising ServiceNow as a Global HR Service Management platform, I have learnt and appreciated HR use cases and processes that I was previously unaccustomed to.These are in the following areas of:

  • HR Service Management (HR Incident, HR SLM, HR Knowledge, HR Problem, HR Change, HR Service Reporting etc...)
  • Case Management (Customer Services)
  • Document and Records Management
  • Workforce Administration(eg. Job Data Change, Reference Requests, etc...)
  • Recruitment
  • Exit Management
  • Leave and Absence Management
  • Employee Relations and Disciplinary
  • International and Mobility Services

This has opened my eyes and increased my appreciation in the complexity of running HR departments in a global organisation. But what it has also proven is what you can do with ServiceNow as a business process enablement platform.

One specific use case that keeps coming up with our ServiceNow and HR projects is around Word Document Generation. If you are familiar with the ServiceNow platform, there isn't an OOTB functionality that allows a user to automatically generate an MS Word Document from a record. In the world of Human Resources, documents (whether they are physical or electronic) are very important artefacts and impact almost all HR use cases and processes. This is most important for Reference Requests as part of Workforce Administration. Why not manage Reference Letters in your ServiceNow platform? So here is an art of the possible...

Art of the Possible

Below is a short video showing the functionality of generating an MS Word Document from the ServiceNow HR application (or any application for that fact).  The functionality can take any field(s) within a particular record and place it within an MS Word Document. This is facilitated by a UI Action, UI Page and a Script Include using WordprocessingML1.


Be mindful that this example is not a polished or complete solution, but shows what is possible.

The Solution

In summary, a UI Action is added to allow a user to execute a "Word Export". This UI Action calls a UI Page.

When triggered, the UI Page is displayed asking for the user to enter a desired document name.

The UI Page then references a Script Include which has the below snapshot of the WordprocessingML:

return gs.getProperty('');

createTheDoc: function() {
var theResult = false;
try {

var table_name = this.getParameter('sysparm_table_name');
var ticket_id= this.getParameter('sysparm_ticket_id');
var file_name = this.getParameter('sysparm_file_name');
var theType =this.getParameter('sysparm_list_name');
theResult = false;
var rowNumber = 0;

var gr = new GlideRecord(table_name);
gr.addQuery('sys_id','IN', ticket_id);

if (!gr.hasNext()) {
return false;

var strXML= this._excelFileStart();
//strXML += this._addCaseHeaders(gr);
//strXML += this._addVariableHeaders(gr);

var gt = new GlideRecord('hr');
strXML+='HR Number: '+gt.number+'';
strXML+='Caller: '+gt.caller_id.getDisplayValue()+'';
strXML+='Priority: '+gt.priority+'';
strXML+='Category: '+gt.category+'';
strXML+='State: '+gt.state+'';
strXML+='Details:- ';


The Script Include then saves the WordML document using the document name the user entered but with a .doc filename extension. The document is then saved in the attachments table and triggers an open.

This solution doesn't necessarily just apply to HR use cases. Think of what other user cases would have a need for an MS Word Document generation?