- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2022 01:30 PM
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
Solved! Go to Solution.
- Labels:
-
Architect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 02:16 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2025 06:09 AM
This code does not convert the HTML content properly into a word file like it gets done for pdf file.