Formatting Error When Setting Date Field
Hi, when I’m writing a server side script, I seem to always have trouble setting new Date() on a field. The error I get says the format is wrong:
{“type”:”error.SuiteScriptError”,”name”:”INVALID_FLD_VALUE”,”message”:”Invalid date value (must be M/D/YYYY)”,”stack”:
But I’m formatting it using the format API and when I log my variable it’s ‘3/18/2020’, seemingly the correct format. The odd thing is I only get this error when using record.setValue(). When I do record.submitFields(), it’s fine.
Any suggestions on how to fix this?
Use setValue with a Date object as the value.
Use setText with a N/format module formatted string as the text.

That worked. Thanks!
set text is not wokring… the vlaue is not being reflected
I tried this code, but it doesn’t work, still “INVALID_FLD_VALUE”. What should be the problem?
var startDate = format.format({type: format.Type.DATE, value: new Date(values.custrecord_startdate)}) ; var endDate = format.format({type: format.Type.DATE, value: new Date(values.custrecord_bits_enddate)});

Does your date object look correct when you log it?
Yup its correct. I found the solution. Need to convert the field into a date field. I didn’t have to use format
newRecord.setValue(cfg.START_DATE, new Date(values.startdate));