Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Unable to Display Images in Word Document Generated via GlideSysAttachment

prithviaram
Tera Contributor

Requirement:
I am looking for a solution that allows displaying an image inside a Word document generated using the background script shown below.

Problem Statement:
I need to embed and display an image inside a Word document that is created through a server-side script.

Code:

 
// ===== Get Target Record =====
var userGR = new GlideRecord('sys_user');
userGR.get(gs.getUserID());

// ===== File Name =====
var now = new GlideDateTime();
var safeStamp = ('' + now.getDisplayValue()).replace(/[:\s]/g, '_');
var fileName = 'ServiceNow_Explanation_' + safeStamp + '.doc';

// ===== HTML Content =====
var html =
'<html><body style="font-family:Calibri;font-size:11pt;">' +
'<h1>What is ServiceNow?</h1>' +
'<p>ServiceNow is a cloud-based platform used to manage and automate digital workflows.</p>' +
'<p>It is widely used for IT Service Management (ITSM) to manage incidents, service requests, problems, and changes.</p>' +
'<p>The platform enables automation through workflows, Flow Designer, integrations, and low‑code application development.</p>' +
'<p>ServiceNow also supports HR Service Delivery, Customer Service Management, Security Operations, and IT Operations.</p>' +
'<p>Overall, ServiceNow helps organizations improve efficiency and deliver better digital services.</p>' +
'</body></html>';

// ===== Create Attachment =====
var gsa = new GlideSysAttachment();
var attachmentSysId = gsa.write(userGR, fileName, 'application/msword', html);

if (attachmentSysId) {
    gs.info('Word document created successfully');
} else {
    gs.error('Attachment creation failed');
}

Approaches Tried:
I attempted to display an image by:

  1. Referencing the image directly from the sys_db_image table, and
  2. Converting the image into Base64 and embedding it in the HTML.

Both approaches displayed the image correctly in online HTML previewers, but Word did not render the image. In some cases, Word displayed placeholder text or broken image icons.

Conclusion:
I would like to know whether it is possible to embed and display an image inside a Word document generated through this method in ServiceNow, and if so, what approach works reliably.

0 REPLIES 0