Export record as a word document

CosminM
Tera Contributor

Hi all,

 

I have an unusual request in our company and I know that you can convert the PDF into a Word, but please do not ask why is that not happening.

 

I've used the script from the below post and I've created a UI Action OnClick with that script but nothing is working for me. Normally it had to generate something and attached to the incident.

I did the test in a PDI instance Vancouver version (the other new ones were not available). Also I'm new to ServiceNow and not that good with it or with the scripting part.

What I'm I doing wrong? Or is the script not that good?

 

These are the settings that I have done for UI Action.

CosminM_0-1732791146664.png

 

 

https://www.servicenow.com/community/architect-forum/export-record-as-a-word-document/m-p/2364559#M2...

 

 

 

 

function generate_word(){
	var variables = current.variables.getElements();
	var variablesBody = '';
	for (var j = 0; j < variables.length; j++) {
	var question = variables[j].getQuestion();

	variablesBody = variablesBody + '<tr><td style="background-color:#3388FF;color:white;">' + question.getLabel() + ':</td><td>' + question.getDisplayValue() + '</td></tr>';
	}
	var fieldProperty = gs.getProperty('changerequest.mop.fields');
	var fields = fieldProperty.split(',');
	var body = '';
	for (var i = 0; i < fields.length; i++) {
	var field = fields[i];

	body = body + '<tr><td style="background-color:#3388FF;color:white;">' + current[field].getLabel() + ':</td><td>' + current[field].getDisplayValue() + '</td></tr>';
	}
	var html = '<html><table border = "1">' + body + variablesBody + '</table></html>';
	var attachmentName = current.number.toString() + ".doc";
	var gsa = new GlideSysAttachment();
	var attachmentId = gsa.write(current, attachmentName, 'text/plain', html);
	action.setRedirectURL(current);
}

 

 

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@CosminM 

you cannot create word file within ServiceNow without use of external library or mid server.

You can create PDF file using PDF API.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@CosminM 

you cannot create word file within ServiceNow without use of external library or mid server.

You can create PDF file using PDF API.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader