How to set Date field in Suite Script 2.0
Hi All,
In Suite Script 2.0, setting date is not as simple as setFieldValue(),
Even if you get value using getValue() and try to use setField() , it will try setting value in
format similar to "org.mozilla.javascript.NativeDate@3954f57d".
To fix this issue ,
Step 1: developer should use "N/format" module,
Step 2: format.format() method
format.format({value: DateVariableHere, type: format.Type.DATE}),
Step 3: set this value using setValue()
myRecord.setValue({
fieldId: 'custbody_id',
value: newValue
});
//============== use below code for 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})
});
//======================== end date to date field =====================
Please note: use
Thanks
Netsuite Guru
Download Netsuite Guru Android App
Follow Me on Linkedin
Our FB Page
In Suite Script 2.0, setting date is not as simple as setFieldValue(),
Even if you get value using getValue() and try to use setField() , it will try setting value in
format similar to "org.mozilla.javascript.NativeDate@3954f57d".
To fix this issue ,
Step 1: developer should use "N/format" module,
Step 2: format.format() method
format.format({value: DateVariableHere, type: format.Type.DATE}),
Step 3: set this value using setValue()
myRecord.setValue({
fieldId: 'custbody_id',
value: newValue
});
//============== use below code for 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})
});
//======================== end date to date field =====================
Please note: use
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
});
//============== end use below code for string to date field =======
Thanks
Netsuite Guru
Download Netsuite Guru Android App
Follow Me on Linkedin
Our FB Page
Comments
Post a Comment
Thanks for you message, please join us on Facebook and Linkedin