I am trying to create a button that will add a fil...
# suitescript
p
I am trying to create a button that will add a filter to a saved search and then display the search in a new browser tab. When the button is clicked it is going to the saved search but the filters are not being applied. Any hints on how I can achieve my goal:
Copy code
define(['N/search'], function (search) {
    /**
     * @NApiVersion 2.x
     * @NScriptType ClientScript
     */
    
    var exports = {};
    function pageInit(context) {
    	// TODO
    }
      
    function myButton(context){   
var objSearch = search.load({
    id: 'customsearch1620'
});
var defaultFilters = objSearch.filters;
defaultFilters.push(search.createFilter({
    name: "custbody_myField",
    operator: "anyof",
    values: 6000
}));
objSearch.filters = defaultFilters;
var objSearch_run = objSearch.run().getRange({
    start: 0,
    end: 10
});
window.open('<https://xxxxx.app.netsuite.com/app/common/search/savedsearch.nl?id=1620>');
    }
exports.myButton = myButton;
exports.pageInit = pageInit;
return exports;
});
b
save your search
p
Thanks!
m
You should be able to do this without touching the search by adding a url parameter for the additional filter. E.g.
Copy code
function myButton(context){   
  window.open('<https://xxxxx.app.netsuite.com/app/common/search/savedsearch.nl?id=1620&CUSTBODY_MY_FIELD=6000>');
}
You might need to add the field as an available filter to the search
If you do go with the approach of saving the search, note that there is no reason to retrieve any results in the client script (remove the obSearch.run() line)