ANS-1278 · SUITESCRIPT DEVELOPMENT

How to Create a CSV File with UTF-8 BOM Encoding in NetSuite

NetSuite users can ensure proper character display in CSV exports by prepending a specific Unicode character to the file's contents during creation.

Short answer

To create a CSV file with UTF-8 BOM encoding in NetSuite, prepend the Unicode Byte Order Mark character ('ufeff') to the beginning of the CSV file's contents. This ensures compatibility and correct character rendering when the file is opened by various applications.

Scenario

NetSuite users often encounter issues with character encoding when generating CSV files, particularly when special characters are present. Without the correct encoding, these characters may display incorrectly or as garbled text in external applications. A common requirement is to ensure CSV files are encoded with UTF-8 BOM for broader compatibility.

Solution

To generate a CSV file with UTF-8 BOM encoding, the Byte Order Mark (BOM) Unicode character ('ufeff') must be added at the very beginning of the CSV file's contents. This is typically done when creating the file programmatically using NetSuite's N/file module.The following example demonstrates how to include the 'ufeff' character when creating a file:

javascriptvar objFile = fileModule.create({    name: fileName,    fileType: fileModule.Type.PLAINTEXT,    contents: 'ufeff'+strCSV, // add ufeff to support UTF-8 with BOM    encoding: fileModule.Encoding.UTF8,    folder: FILE_CABINET_FOLDER});

By prepending 'ufeff' to the 'contents' property, the generated CSV file will include the necessary BOM, allowing applications to correctly interpret its UTF-8 encoding.

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant