Embedding External Images in NetSuite Emails

in , , October 21st, 2024

When using NetSuite, companies will often setup email templates that might include images. Most of the time these can be pointed to with <img> tags via the file cabinet, but sometimes the images are external/temporarily generated. This results in the following errors:

  • Blank HTML <img> src attribute
  • <img> src unsetting in email or <img> src not setting

This is almost entirely due to the <img> source being set as a data URI looking similar to this:

data:image/png;base64,iVBORw0KGgoAA ... teOv==

How to Embed External Images in NetSuite Emails

The primary method of eliminating this error is to reconstruct the data URI as a file in NetSuite so that the <img> source attribute can point to a new string. Given a data URI, this is done with the following functions:

  • Split the data URI into the base64 string and its data content using something like:
const base64String = datauri.split(',')[1];
  • Grab the NetSuite folder to hold the image and userID to build the URL:
const userId = runtime.getCurrentUser().id;
  • Save the converted data into a NetSuite file object matching the original data URI description
  • For instance, if the original URI was “data:image/png” then use the following
const netsuiteFile = file.create({
   name: 'qrcode' + userId + '.png',
   fileType: file.Type.PNGIMAGE, //Based on image type
   contents: base64String ,
   description: "QR Code",
   encoding: file.Encoding.UTF8,
   isOnline: true,
   folder: QRCODE_FOLDER_ID
}).save();
  • Load the created image file to retrieve external URL info
const imageFile = file.load({id: netsuiteFile});
  • Retrieve the host domain to complete the URL
const accountDomian = url.resolveDomain({
    hostType: url.HostType.APPLICATION,
});
  • Build the URL string for the <img> src attribute to call
<img src={'https://' + accountDomian + imageFile.url} />

If the generated file needs to be deleted, run a scheduled script to clean the file cabinet and inform users of their time window.

Author: Benjamin Gagliardi


Got stuck on a step in this article?

We like to update our blogs and articles to make sure they help resolve any troubleshooting difficulties you are having. Sometimes, there is a related feature to enable or a field to fill out that we miss during the instructions. If this article didn't resolve the issue, please use the chat and let us know so that we can update this article!


Oracle NetSuite Alliance Partner & Commerce Partner

If you have general questions about SuiteCommerce or more specific questions about how our team can support your business as you implement NetSuite or SuiteCommerce, feel free to contact us anytime. Anchor Group is a certified Oracle NetSuite Alliance Partner and Commerce Partner equipped to handle all kinds of NetSuite and SuiteCommerce projects, large or small!

 
 

Want to keep learning?

Our team of NetSuite professionals has written articles on a wide variety of NetSuite topics, from SuiteCommerce tips, to recommended NetSuite solutions, to available support services, and more! 

Your cart