Anyone else hit an issue where the end user's date...
# suitescript
c
Anyone else hit an issue where the end user's date format is impacting a scripted search that is using a date? I tried this, and it works fine for me, but not another end user who the script is running for later:
var startDate=format.parse({value:"2020-01-01T12:00:00Z",type:format.Type.DATETIME})
var noteSearchObj=search.create({ type: "note", filters:[ [ ["customer.internalid","anyof",custNSID], "AND", ["notedate","onorafter",startDate] ] ],
b
standard advice: use Date's or N/format
parse expects the input string to be in the current user's format
c
Let me try format instead.
b
wont help
c
Ahh. Any ideas? I have not run into this before.
b
"2020-01-01T120000Z" is almost in ISO 8601 format
c
Yeah, my format is 2020-01-01 120000... But their format is that weird mm/dd/yy 12:00 format.
b
the Date constructor can create Date's from ISO-8601 format so use
var startDate = new Date("2020-01-01T12:00:00.000Z")
add on the .000 milliseconds
c
k, I'll try it.
nah, still returns the same error... "INVALID_DATE_VALUE_1_MUST_MATCH_2"
b
full error message?
c
here's the latest one while messing around. Essentially the same error, about the format. {"type":"error.SuiteScriptError","name":"INVALID_DATE_VALUE_1_MUST_MATCH_2","message":"Invalid date value 2020-01-01T120000.000Z (must match yy-MM-dd h:mm a)","stack":["createError(N/error)","queryLatestUserNote(/SuiteScripts/O2_SuiteScripts/O2_UE_Customer_Update_Last_User_Note.js:99)","beforeSubmit(/SuiteScripts/O2_SuiteScripts/O2_UE_Customer_Update_Last_User_Note.js:38)"],"cause":{"type":"internal error","code":"INVALID_DATE_VALUE_1_MUST_MATCH_2","details":"Invalid date value 2020-01-01T120000.000Z (must match yy-MM-dd h:mm a)","userEvent":"beforesubmit","stackTrace":["createError(N/error)","queryLatestUserNote(/SuiteScripts/O2_SuiteScripts/O2_UE_Customer_Update_Last_User_Note.js:99)","beforeSubmit(/SuiteScripts/O2_SuiteScripts/O2_UE_Customer_Update_Last_User_Note.js:38)"],"notifyOff":false},"id":"","notifyOff":false,"userFacing":false}
b
that doesnt look like you put in a Date
what code did you use
c
The date is in the error: Invalid date value 2020-01-01T120000.000Z That was trying with the idea you had. But, same error when it works for me, and someone else runs it with a non ISO date format.
b
Copy code
["notedate","onorafter",new Date("2020-01-01T12:00:00.000Z")]
c
Yeah, tried that. Same error... One sec, I'll show you.
See, this is what happens with that one: {"type":"error.SuiteScriptError","name":"INVALID_DATE_VALUE_1_MUST_MATCH_2","message":"Invalid date value Wed Jan 01 040000 PST 2020 (must match yy-MM-dd h:mm a)","stac
b
thats more like it
c
Same error...?
b
Wed Jan 01 040000 PST 2020 is new Date("2020-01-01T120000.000Z").toString()
c
Right... Bu, NetSuite is trying to use the client format, for server side code... 😕
b
same error, but i wouldnt expect to get an ISO-8601 string as the format if you used a Date
sadly the date format is expected(yy-MM-dd h:mm a) doesnt include seconds
you can use format.format to get a date time that will include seconds like: yy-MM-dd hmmss a
you will have to strip off the seconds
c
Right, but that is my UI format. If I set it to write that format, it works perfect for me. But, when someone else runs the script, witha different UI date format, and it breaks. That's what I mean by I've never had this happen before. The client side formats are being used on the server side, which I've never had happen...???
b
scripts use the format of the current user
for a user event script, that would be the current user saving the record
same for suitelet and restlets
c
Which means that this can never work now... I can't know what date format some rando decides to use... lol
b
N/format will format a Date to a string in the current user's settings
e
Example of a working Date filter, a
Date
passed in to `N/format.format`:
Copy code
["custrecord_billend" , search.Operator.ON,format.format({value: new Date(), type: format.Type.DATE})]
b
that one will work, but wont include time
e
Little simpler since it's just using the current timestamp, but as long as you can get a correct
Date
object, you should just be able to use
N/format.format
Well, he could just switch it to
DATETIME
b
Datetime includes seconds, which is not the request format
c
Nah, tried format as well, no luck. The date has to be 2020-01-01, not the current date...
e
The concept still applies
format.format({value: new Date("2020-01-01"), type: format.Type.DATETIME})
c
I'll try it again, before saying it doesn work... 🙂
e
The general idea is: 1. Turn the incoming date representation into a
Date
instance representing the correct timestamp 2. Use
N/format.format
to turn the
Date
instance into a string as the
format()
method automatically uses the current user's (or system's) date format preference
b
im not disagreeing what that, but there is no type that will output a datetime string without seconds
you have to chop out the seconds
c
wow, that one really doesn't work... lol... ["notedate",search.Operator.ONORAFTER,format.format({value:new Date("2020-01-01"),type:format.Type.DATE})] = {"type":"error.SuiteScriptError","name":"INVALID_DATE_VALUE_1_MUST_MATCH_2","message":"Invalid date value NaN-NaN-NaN (must match yy-MM-dd h:mm a)","stack":["crea
b
it will work if you use ["notedate",search.Operator.ONORAFTER,format.format({value:new Date("2020-01-01T120000.000Z"),type:format.Type.DATE})]
you will lose out on the hour/minutes, but it should work
c
The problem that I'm having is that I have to get data that is after the first only. And, that is causing an issue becuase I don't knwo what format every person is apparently using... 😕 Ahh, yeah, that's the way I had it previously... I'll try again...
e
I suppose I've never run into the issue with seconds. Generally when I'm working with dates, I'm using
moment.js
, and it's a matter of `format.format(moment(...).toDate())`whether there's a Time involved or not
sorry I can't be of more help
👍 1
c
Okay, now we are back to where it works for me... I'll try switching my format and see if it still works... 🙂 Maybe there was just a typo... #fingerscrossed
Yep that did it... It's working again in each format. I'll have to undo my recent code to find what I mistyped... ? Thanks!
So it was a combination of both of your suggestions. Adding the .000 to the timestamp, and formatting it to only Date. Guess I've just never hit that combination of items before... 😄