Setting a Date value in Date type custom field in NetSuite and change the timezone

When we fetch a date value format from a custom field (Type is date) we get the format as “2022-07-13T07:00:00.000Z” ISO format. we have to convert this form into M/D/YYYY format. For that use this syntax below:

Module: N/format

var dateNeededByNew = rec.getValue({field:date}); // 2022-07-13T07:00:00.000Z
var formattedDateString = format.format({
value : dateNeededByNew,
type:format.Type.DATE //If we need time also “type:format.Type.DATETIMETZ”

}) //Results *7/13/2022 (M/D/YYYY format)

Now the date format is like M/D/YYYY.

Before setting this value to the custom field(also date field) must do this :new Date(formattedDateString)

that is, 
record.submitFields({
    type: record.Type.SALES_ORDER,
    id: soId,
    values: {
        custbody_updated_due_date: new Date(formattedDateString)
    },
    options: {
        enableSourcing: false,
        ignoreMandatoryFields : true
    }
});
This way we can set the date value. Otherwise it shows an error.

Change Timezone

Module: N/format

Holds the string values for supported time zone formats. Changing the current date and time to another timezone.

var date = new Date(); //Mon Aug 24 2015 17:27:16 GMT-0700 (Pacific Daylight Time)
var BRISBANE = format.format({
    value: date,
    type: format.Type.DATE,//If time also needed:"type:format.Type.DATETIME"
    timezone: format.Timezone.AUSTRALIA_BRISBANE  //can Change time zone names
}); //Returns "8/25/2015 9:27:16 am"

Leave a comment

Your email address will not be published. Required fields are marked *