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

This code does not convert the HTML content properly into a word file like it gets done for pdf file.