Running into an issue where a loaded saved search ...
# suitescript
r
Running into an issue where a loaded saved search is throwing an "Unexpected Error". NetSuite support has so far been unhelpful. The saved search runs natively without issue, with a filter for date. Trying to run it programatically adding the start & end dates.
Copy code
let filterDateStart = Nsearch.createFilter({
                name: 'trandate',
                operator: Nsearch.Operator.ONORAFTER,
                // values: runDates.startDate,
                values: '07-01-2021',
            });
This code, whether with values as a date string like shown, or as a Date object (the commented value), doesn't return an error, but when I try to run the search with this filter pushed, then it errors. Anyone see any issues with creating the filter like this?
b
Create the search in the ui
Then log the filters and columns in code
s
You also did not share how you added to the filters to the loaded search. Are the filters of the search an expression or just regular filters?
r
sorry, full date handling
Copy code
let filterDateStart = Nsearch.createFilter({
                name: 'trandate',
                operator: Nsearch.Operator.ONORAFTER,
                // values: runDates.startDate,
                values: '07-01-2021',
            });
            let filterDateEnd = Nsearch.createFilter({
                name: 'trandate',
                operator: Nsearch.Operator.ONORBEFORE,
                // values: runDates.endDate,
                values: '07-31-2021',
            });

            searchUnbilled.filters.push(filterDateStart);
            searchUnbilled.filters.push(filterDateEnd);
and they're just regular filters
although based on what @battk, I'm thinking I should be using the column ID of the actual filter from the saved search, and not just creating two new filters and pushing them onto the filter stack of the saved search?
j
I’ve definitely pushed search filters on before. Like so:
Copy code
mysearch.filters.push(search.createFilter({name: 'trandate', operator: search.Operator.ONORAFTER, values: format.format({value: my_date, type: format.Type.DATE})});
maybe you need the format.format bit
👍 1
n
anytime I work with dates and searches, format.format({})
r
that could be what I'm missing. I'll attempt that tomorrow first thing
late reply, but N/Format was indeed what solved it. Thanks for the tip.