how do i add filters dynamically into the search.c...
# suitescript
r
how do i add filters dynamically into the search.create ? like if this then filter is salesorder else purchaseorder ..something like that irrelevant of the search .. search may have more filters i do not want to load the search i suppose to push( 'and ') and push([ filter ]) into the searchobj.filters?
u
can you share more specific conditions? Here is the simple example, you can use any programming logic with this and you can also use filter expressions
_var_ dynamicFilter = null;
if (condition) {
    
dynamicFilter = search.createFilter({})
} else {
    
dynamicFilter = search.createFilter({})
}
_var_ filters = searchObj.filters;
filters.push(dynamicFilter);
searchObj.filters = filters;
r
thanks i will try that
this is also working, i dont understand the specificity of search.createFilter()
Copy code
if (dataFilters.b_dateflag == 'Expiry') { // expire date

filters.push("AND");
filters.push(["expirationdate", "onorbefore", "today"]);


} else if (dataFilters.b_dateflag == 'Do not ship after') { // DO NOT SHIP Custom field
filters.push("AND");
filters.push(["custitemnumber1", "onorbefore", "today"]);

}

inventorynumberSearchObj.filterExpression = filters;
u
That was just an example, I also said at the end that you can use filter expressions as well.
r
right, thanks
163 Views