So... is this just a NetSuite quirk where I can't ...
# suitescript
r
So... is this just a NetSuite quirk where I can't use filter expressions when searching by dates?
Copy code
let accountingPeriodSearch = Nsearch.load({
            id: uvLibID.savedSearch.ACCOUNTING_PERIOD,
        });
        let searchStartDate = Nformat.format({
            type: Nformat.Type.DATE,
            value: startDate.toDate(),
        });
        let searchEndDate = Nformat.format({
            type: Nformat.Type.DATE,
            value: endDate.toDate(),
        });
        accountingPeriodSearch.filters.push(Nsearch.createFilter({
            name: uvLibID.field.ACCOUNTING_PERIOD.START_DATE,
            operator: Nsearch.Operator.ON,
            values: searchStartDate,
        }));
        accountingPeriodSearch.filters.push(Nsearch.createFilter({
            name: uvLibID.field.ACCOUNTING_PERIOD.END_DATE,
            operator: Nsearch.Operator.ON,
            values: searchEndDate,
        }));
        accountingPeriodSearch.run();
works fine, but if I try to use filter expressions with the same params instead
Copy code
let accountingPeriodSearch = Nsearch.load({
            id: uvLibID.savedSearch.ACCOUNTING_PERIOD,
        });
        let searchStartDate = Nformat.format({
            type: Nformat.Type.DATE,
            value: startDate.toDate(),
        });
        let searchEndDate = Nformat.format({
            type: Nformat.Type.DATE,
            value: endDate.toDate(),
        });
        accountingPeriodSearch.filterExpression = [
            [ uvLibID.field.ACCOUNTING_PERIOD.START_DATE, Nsearch.Operator.ON, searchStartDate ],
            [ 'AND' ], // Tried with & without, no difference
            [ uvLibID.field.ACCOUNTING_PERIOD.END_DATE, Nsearch.Operator.ON, searchEndDate ],
        ];
        accountingPeriodSearch.run();
NetSuite throws a
Copy code
{"type":"error.SuiteScriptError","name":"SSS_INVALID_SRCH_FILTER_EXPR","message":"Malformed search filter expression.","id":"",...}
j
try removing the square brackets from around the ‘AND’
☝️ 1
e.g. `accountingPeriodSearch.filterExpression = [ [ uvLibID.field.ACCOUNTING_PERIOD.START_DATE, Nsearch.Operator.ON, searchStartDate ], ‘AND’ , // Tried with & without, no difference [ uvLibID.field.ACCOUNTING_PERIOD.END_DATE, Nsearch.Operator.ON, searchEndDate ], ];
r
@jen derp. thank you. My duck didn't catch that one.
rubber duck debugging 2
j
My duck got turned into a cat toy
r
I tried that with mine, but they usually belly flop and demand attention
j
oh I didn’t INTEND for it to be a cat toy. Their choice, not mine.