Purpose
This article explains how to handle timezone discrepancies when setting date fields in NetSuite via a Map/Reduce script, especially when using ISO 8601 UTC date strings from external systems. This ensures the correct calendar date appears in the NetSuite UI, regardless of the account’s timezone configuration.
Problem Overview
External systems often send date values in UTC ISO 8601 format, for example:
"2025-07-21T00:00:00.000Z"
When we create a Date object in JavaScript with this value, it represents midnight UTC. NetSuite stores dates in UTC but displays them in the user’s account timezone (often US timezones, e.g., EDT, PDT).
Issue Example
If the NetSuite account is set to EDT (UTC-4):
"2025-07-21T00:00:00.000Z"is July 20, 2025, 8:00 PM EDT- NetSuite displays the date as July 20, 2025, not the intended July 21, 2025
This leads to a one-day offset in the user interface due to timezone conversion.
Solution
To avoid this issue, the time portion must be stripped and only the intended calendar date should be preserved before setting the value in NetSuite.
Implementation Steps
/**
* Preserving intended calendar date across timezones
*/
// Step 1: Parse UTC ISO string into a JavaScript Date object
var utcDateString = "2025-07-21T00:00:00.000Z"; // Example input
var utcDate = new Date(utcDateString); // JS Date object in UTC
// Step 2: Create a new Date using only the UTC year, month, and date
var localDate = new Date(
utcDate.getUTCFullYear(),
utcDate.getUTCMonth(),
utcDate.getUTCDate()
);
// Step 3: Convert to NetSuite Date object using the N/format module
var nsDate = format.parse({
value: format.format({
value: localDate,
type: format.Type.DATE
}),
type: format.Type.DATE
});
// Step 4: Set the date field on a NetSuite record
record.setValue({
fieldId: 'custom_date_field', // replace with actual field ID
value: nsDate
});