The error is encountered when setting a string value for a Date field, as shown in the code snippet below:
var record = record.load({
type: params.type,
id: params.id,
isDynamic: true
});
// Assuming Date Format is D/MM/YYYY
var datestring ='22/11/2022';
record.setValue({fieldId:'trandate',value:datestring});
record.save();
Solution
The error being thrown by NetSuite is an expected behavior. Date field cannot accept string objects values. To be able to pass a Date value to this type of field, user must first convert the string value to Date Object using format.parse(options) under N/format module.
var record = record.load({
type: params.type,
id: params.id,
isDynamic: true
});
// Assuming Date Format is D/MM/YYYY
var datestring ='22/11/2022';
var formatteddatetime = format.parse({value:datestring , type: format.Type.DATE});
record.setValue({fieldId:'trandate',value:formatteddatetime});
record.save();