Export record as a word document

Vidya Shree
Kilo Sage

Hi All,

 

We have a requirement to have an option to export a record as a word document.

I looked through various posts in the community but could not find anything.

Has anybody worked on similar requirement? or any idea on how this can be achieved?

 

Thanks in advance

1 ACCEPTED SOLUTION

Vidya Shree
Kilo Sage

Hi All,

 

I was able to achieve this with the below code.

I have used UI action on click of which word document will be created and attached the record

 

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);

View solution in original post

5 REPLIES 5

OlaN
Giga Sage
Giga Sage

Hi,

I've never heard of anyone asking for a solution to export a record to Word before.

Would it be possible to use the built-in Export to PDF function, and then manually generate a Word document from the PDF using Acrobat?

Jugmaz
Kilo Sage

me either didn't heard that one even want's to have word from SN.

if you manage to do that, please share.

i would suggest on something that is semi-automated with TXT file export and so on...

 

Vidya Shree
Kilo Sage

Hi All,

 

I was able to achieve this with the below code.

I have used UI action on click of which word document will be created and attached the record

 

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);

ok, so you actually creating TXT document with HTML markup.

well, if that works 😉