What is the Syntax for inserting a Javascript Date into a Search in SuiteScript?
var start = new Date(2019, 0, 1); var end = new Date(2019, 0, 31); var itemsSearch = searchModule.create({ type: 'salesorder', filters: [ ['type', 'anyof', 'SalesOrd'], 'AND', ['datecreated', 'within', start, end], ], columns: [....] });
I am trying to add dynamic dates to a Search. Is this the correct Syntax for adding a javascript Date as a parameter to the search?
More specifically, they need to be in the format specified by the preferences of the user running the script. After you’ve created your Date
objects, you can use N/format.format()
to output them as strings in the correct format.
If you don’t need them as Date
s for further calculation or anything, you could just format them directly.
Should end up looking something like:
var startStr = format.format({type: format.Type.DATE, value: new Date(...)}); var endStr = format.format({type: format.Type.DATE, value: new Date(...)});; ... filters: [['datecreated', search.Operator.WITHIN, startStr, endStr]] ...
Cheers bro in a land not far away you are known as the Stoic Beast of Netsuite development. Thanks, man your tutorials are the best. Without your explanations, I would have long given up on Netsuite. You never disappoint.
How about filtering by date and time. If I change the code above to format.Type.DATETIME or format.Type.DATETIMETZ then I get UNEXPECTED_ERROR.
Dates in filters need to be strings in ‘D/M/YYYY’ format