问题
I have a custom record that has a field for an item and a field for location. I have a saved search on that record that already has the columns I want and some beginning criteria that will always be needed. I want to use this search when I am on a Sales Order. I want to store an array of all the item internal ids and location ids on the lines and then pass that as a dynamic filter to this search in SuiteScript 2.0.
According to the documentation this can be done. On the search.Filter page it says "You create a search filter object with search.createFilter(options) and add it to a search.Search object that you create with search.create(options) or load with search.load(options)." However, I do not see any parameter on search.load for this nor a code example of adding it after the load. All examples of using search.Filter are in using it in the search.create function
Thank you for any help you can give.
回答1:
You can push the filter object to the filters property of the search.
searchObj.filters.push(filterObj);
回答2:
I will list the steps in a simple way so that you can understand it better. After you get the hang of it,you can edit it the way you want
STEPS :
1.Load saved search (say objSearch )
2.Copy the filters from objSearch into a new array (say defaultFilters )
3.Create a new array (say customFilters ) to store the new filter and we push it into defaultFilters
4.At last, we copy the modified defaultFilters back into objSearch and run the saved search
//Load saved search into objSearch
var objSearch = search.load({
id: 'savedsearchid'
});
//Copy the filters from objSearch into defaultFilters
var defaultFilters = objSearch.filters;
var customFilters = [];
//We will add the new filter in customFilters
customFilters = ['postingperiod', 'ANYOF', '1'];
//We will push the customFilters into defaultFilters
defaultFilters.push(customFilters);
//We will copy the modified defaultFilters back into objSearch
objSearch.filters = defaultFilters;
//Run the saved search
var objSearch_run = objSearch.run().getRange({
start: 0,
end: 10
});
回答3:
var mySearch = search.load({ id: '851' });
var defaultFilters = mySearch.filters;
var customFilters = {};
customFilters = {"name":"custrecord_customer","operator":"anyof","values":["64468"],"isor":false,"isnot":false,"leftparens":0,"rightparens":0};
defaultFilters.push(customFilters);
mySearch.filters = defaultFilters;
来源:https://stackoverflow.com/questions/47578686/suitescript-2-0-add-filters-to-saved-search-in-script