``` var datestr = '2016-03-12 13:00:00...
# suitescript
s
Copy code
var datestr = '2016-03-12 13:00:00';
            
            var date = obj.moment(datestr).toDate();
            log.debug("date", date);
            log.debug("typeof date", typeof date);
    
            newRec.setValue({
                "fieldId": "notedate",
                "value": date
            });
What’s the gotcha with setting datetimes? do you want to set it to a date obj or a datestr? right now its a date object, but only the date is correct, the time is not correct when I look at the note in netsuite
s
Keep in mind that SuiteScript always run in Pacific timezone, and dates are recorded accordingly. You then see the date/time reflected in your own timezone (per preferences).
b
suitescript doesnt always run in pacific
scripts run by system run in the timezone of the server (na0 and na2 would be pacific)
scripts run by a user run in the timezone selectec in the user's time zone preferences
there are 2 sane ways to set date fields: create a Date and use the date as the value create a date and convert it to a string using the format module
for your case, you can create a date using an 8601 formatted datetime string or a unix timestamp if you give me the timezone of your date, i can give examples
s
thanks for pointing out that it's the server timezone. na1 must also be Pacific then too, because all of our server scripts are in that timezone
@battk I have heard several people say that "scripts run by a user run in the user;s time zone preference" what does that mean exactly? Every script run in our environment, whether it's a restlet, suitelet, map/reduce, scheduled, or user event is always in pacific, even though we are set to Eastern. I have not yet done any date scripting in a client script to see if it is the same. Is it just client scripts that run in the user's timezone?
s
8601 formatted datetime string. ok lemme try that
@battk
Copy code
var mDate = obj.moment("2016-03-12 13:00:00").toISOString();
would something like that work?
b
no
s
you need to give moment an ISO string, or a format. otherwise results are unpredictable.
b
what timezone do you want
s
mountain time would be good
MST
b
mountain time is gmt -7
s
yes
b
to get UTC time, you would add 7 hours to your date
right now, its 6 hours due to day light savings
the string you want is 2019-03-12T190000.000Z
newRec.setValue({ "fieldId": "notedate", "value": new Date('2019-03-12T190000.000Z') });
i may be off by an hour
s
Copy code
{
  "type": "error.SuiteScriptError",
  "name": "INVALID_FLD_VALUE",
  "message": "The field notedate contained more than the maximum number ( 11 ) of characters allowed.",
  "stack": [
    "anonymous(N/serverRecordService)",
    "get(/SuiteScripts/repo/restlets/KwaPlayTime.js:36)",
    "anonymous(N/serverRecordService)"
  ],
  "cause": {
    "type": "internal error",
    "code": "INVALID_FLD_VALUE",
    "details": "The field notedate contained more than the maximum number ( 11 ) of characters allowed.",
    "userEvent": null,
    "stackTrace": [
      "anonymous(N/serverRecordService)",
      "get(/SuiteScripts/repo/restlets/KwaPlayTime.js:36)",
      "anonymous(N/serverRecordService)"
    ],
    "notifyOff": false
  },
  "id": "",
  "notifyOff": false,
  "userFacing": false
}
they limit the field to 11 characters length.
b
some datetime fields suck and require you to use the format module
s
eh, i’ll try that out in the morning. thanks for the ideas @battk et al.
b
newRec.setValue({ "fieldId": "notedate", "value": format.format({value: new Date('2019-03-12T190000.000Z'), type: format.Type.DATETIMETZ}) });
s
ok lets give it a whirl
same error, lemme log out what format is spitting out
b
i actually seem to recall the note field being more annoying than usual, it separates date and time into 2 fields, notedate and time
s
yeah you are correct… couple screenshots coming
b
newRec.setValue({ "fieldId": "notedate", "value": format.format({value: new Date('2019-03-12T190000.000Z'), type: format.Type.DATE}) });
newRec.setValue({ "fieldId": "time", "value": format.format({value: new Date('2019-03-12T190000.000Z'), type: format.Type.TIMEOFDAY}) });
s
none of those worked 😕
message has been deleted
so when you edit a note, the fields are seperate ^^^
message has been deleted
however the browser explorer says its a datetime all in one field 😕
message has been deleted
this is all I see thats available on the browser
b
wrong tab you want records browser, not schema browser
s
message has been deleted
looks like I need to set
time
and
notedate
b
are you sure these didnt work? The time might be wrong, but it didn't throw an error for me newRec.setValue({ "fieldId": "notedate", "value": new Date('2019-03-12T190000.000Z') }); newRec.setValue({ "fieldId": "time", "value": new Date('2019-03-12T190000.000Z') });
s
yep, looks like date objects for both is where it’s at. ty @battk