Hi, I have a Suitelet that exposes two date fields...
# suitescript
k
Hi, I have a Suitelet that exposes two date fields (date from and date to). I am trying to grab the user input date in the suitelet and use them as a saved search criteria within the script. Here is a snippet of code I am using to achieve so, where dates are being obtained from `urlParams`:
Copy code
var deliveryDateFrom = format.format({
    value: new Date(urlParams.custpage_delivery_date_from),
    type: format.Type.DATE
});
var deliveryDateTo = format.format({
    value: new Date(urlParams.custpage_delivery_date_to),
    type: format.Type.DATE
});

var deliverydatefilter = search.createFilter({
    name: 'shipdate',
    operator: 'within',
    values: [deliveryDateFrom, deliveryDateTo]
});
objSearch.filters.push(deliverydatefilter);
The issue I am having is when I format the dates obtained from
urlParams
using
format.format
, the dates I am obtaining is one day behind the dates entered by the users. For example: user enters range of
6/15/2022 to 6/18/2022
, after using
format.format
on those dates, I receive
6/14/2022 to 6/17/2022
. What is the issue with my code?
a
almost certainly a timezone issue. you're only caring about the date, but a date object HAS a time associated with it too. it will use its own local time to interpret a date, but if you've removed the time data, it will just assume midnight UTC i think? and then your TZ offset will take it to a different date
I think the simplest way to fix this is probably in the client side before you send to your suitelet. create
new Date
objects client side with the values from the user. and take the
startDate.valueOf()
and for end date, and then pass those ints as params instead. and then recreate your date objects with the ints without the use of the format module
k
Thank you! I did realize as well that it was a timezone issue. I was wondering if NS had any method of getting just the date from a datetime field without changing the timezone
b
date type fields dont really go into timezone stuff
it doesnt have any timezone logic, all things are basically pacific time for date fields
date time fields are the ones that respect timezones
that said, your logic looks questionable, it takes a date string and converts it to date, and then back to a date string
which doesnt really do anything interesting except insert a bug when the date format uses a format unrecognized by the Date constructor
k
right. what would you suggest to do here? Is my best bet to parse the date from the datetime string and use it in the saved search filter?
b
do nothing, just put the string you get from the url parameters into the search filter