Set the Date field in Suite Script

In Suite Script 2.0, setting date is not as simple as setFieldValue()

To fix this issue,
Step 1: The developer should use the “N/format” module,
Step 2:  format.format() method
             format.format({value: DateVariableHere, type: format.Type.DATE}),
Step 3:  set this value using  setValue()

//============== Use the below code for the date to date field ================

var myDate =  myRecord.getValue({
       fieldId: 'custbody_date_one
});   
myRecord.setValue({
       fieldId: 'custbody_date_two',
       value: format.format({value: myDate , type: format.Type.DATE})
});

Use the parse method to parse from String/date/number to date.
//============== Use below code for string to date field =========

var myDateString= "04/26/2020";
var parseDate = format.parse({
       value: myDateString,
       type: format.Type.DATE
}); 

Leave a comment

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