Afternoon, Has anyone ever come across an issue wh...
# suitescript
k
Afternoon, Has anyone ever come across an issue where you have a date in the format
2001-5-29
in a string and then use
new Date('2001-5-29')
then set the value to a date field in NetSuite. Then when viewing the record in NetSuite after saving the record the date ends up being
28/05/2001
. This is happening when using
new Date
and when using
format.parse
. It is mighty mighty strange. FYI this is running in a Map/Reduce.
b
its 2001-5-29 00:00 pacific time
which may or may not be the same day in different timezones
k
I understand that but consider that i am telling netsuite to set the date to the value that i want it as it should just set the value as i have told it to.
Never come across this issue before today.
b
are you trying to hardcode to date field?
or is there logic behind this
k
getting date from a file in getInputData, sorting data in map then passing to a record updates object and using new Date on the date from the file.
all logs are the correct dates and types
b
use moment timezone to interpret the date string in whatever timezone you want
N/format will only help you going from netsuite formats to a Date object that is in the Pacific timezone
k
So your saying even though i am telling NetSuite to set a date object of
"2001-05-29T00:00:00.000Z"
to a date field. Netsuite will then change my date to the day before?
b
what timezone is your company timezone?
k
not that it should matter but UK.
b
thats a timezone that you can get to work
k
Well i will need to look into this more. If i give a date to set into a date field then i don;t expect netsuite to change that date
b
using
new Date("2001-05-29T00:00:00.000Z")
will create a Date whose string output looks like
Mon May 28 2001 17:00:00 GMT-0700 (Pacific Daylight Time)
the Date constructor knows how to interpret iso-8601 strings
when you set a field with that Date, then netsuite converts the date to a string in the current user's timezone
k
ah so as my script is running as admin it will use the server time?
b
not really
a map/reduce will run using the system user
that user's timezone will match the company's timezone
k
So in this case i am running the ma reduce and my time zone is set to UK
record is running also in dynamic mode.
b
to be clear, i would double check which timezone is setup in the company information
there is no time zone named UK
k
My time zone GMT company timezone GMT
b
working with Dates generally involves understanding that
2001-05-29T00:00:00.000Z
and
2001-05-28T17:00:00.000-07:00
represent the same Date
k
Thanks @battk this is a new one on me. i've set loads of dates before and never had to set anything like a timezone.
Will get it sorted i'm sure.
b
and then understanding that NetSuite has to choose from one of the many string representations of a Date
the spoiler is that it will choose the representation that match's the current user's timezone
k
understood. Thanks for your time.