Hi I'm trying to set the default date to the form ...
# suitescript
s
Hi I'm trying to set the default date to the form field, so which format do I need to use var toDateField = form.addField({ id: 'custpage_to_date', type: serverWidget.FieldType.DATE, label: 'To Date' }).isMandatory = true; toDateField.defaultValue = "2024_02-15;//YYYY-MM-DD
a
It should be a date, you could use the
N/format
module. Even if it accepts a date string you are mixing formats:
2024_02-15
you should use:
2024-02-15
or
2024/02/15
I don't believe
_
is a valid date separator.
s
Oh that's a mistake, thanks
Nope it's not working for any format😟
c
@Sagar Hiray Have you tried using a Date object?
s
Yes
Default values for other fields like select and text it's working
c
just to point this out: in the code you pasted above, there's no end quote after your date string.
b
you have both choices here
you can either use a Date, or a string that matches the current user's date format
if you insist on using a string, then you will probably need to use N/format to convert a Date into a string matching the user's date format since this is probably user facing
s
if we remove .isMandatory = true; then it will works, but want that
b
set isMandatory on a different line, its not a fluent interface where you can chain methods together