- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 02:57 AM
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.
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);
}
Solved! Go to Solution.
- Labels:
-
Architect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 06:07 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 06:07 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader