Friday, March 29, 2019

SuiteScript > How to set a date/time field based on the company time zone setting.

The following code makes use of the APIs nlapiLoadConfiguration and nlapiSetDateTimeValue to set a date/time field based on the company specified time zone at Setup > Company > Company Information.

var record = nlapiLoadRecord('customer', 1234);

var companyInfo = nlapiLoadConfiguration('companyinformation'); //Load company information
var companyTimeZone = companyInfo.getFieldValue('timezone'); //Get the company time zone
var myDate = new Date("August 8, 1977 12:01:00")
var myDate = nlapiDateToString(myDate, 'datetimetz');

record.setDateTimeValue('custentity_datetime', myDate, companyTimeZone); //Set the date/time field using the company time zone setting


No comments:

Post a Comment