RE: 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?

nathanw Rookie Asked on September 11, 2019 in SuiteScript.
Add Comment
2 Answers
Best answer

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 Dates 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]]
...

Beginner Answered on September 11, 2019.

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.

on October 8, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.