Is there a trick to setting the default value of a...
# suitescript
a
Is there a trick to setting the default value of a date field on a custom suitelet form? I've tried using the raw date value, stringifying it with different formats, and using the N/format
parse
and
format
methods. Everything I try either gives me the "invalid field value" error or the "date value 1 must match 2" error.
s
I usually use moment in combination with the
var dateFormat = runtime.getCurrentUser().getPreference({name: 'DATEFORMAT'})
, and set with a value like
moment('whateverthedateis').format(dateFormat)
Kidna depends where I am getting the date from
e
in 2.0 a field date is expecting a new Date() object in the right format set on your general preferences or user preferences
b
no real trick beyond using a valid date
share your code if you want specific advice
a
Copy code
form.addField({
  id: 'custpage_date',
  label: 'Date',
  type: ui.FieldType.DATE
}).defaultValue = new Date(date);
This is basically what I'm trying to do. A native date object doesn't work.
s
what is this
date
inside of the new Date() call, it might be in the wrong format so the
new Date()
is not interpreting it correctly, if you just want today, then
new Date()
will suffice
b
Your code is unlikely to work unless date is a number or an iso 8601 string