我正在尝试加载已保存搜索的列表,其类型为' customer'。我可以加载所有搜索但是为了让我确定保存的搜索是否是客户保存的搜索,我需要在每个结果上调用search.load()然后检查searchType。我遇到了治理问题。
我收到错误(无效的搜索过滤器),下面是过滤器。
如何过滤搜索客户保存的搜索?
require(['N/search', 'N/record'],
function GetSavedSearches(search, record) {
var records = new Array();
var typeFilter = search.createFilter({
name: 'Type',
operator: search.Operator.ANYOF,
values: 'customer'
});
var mySearch = search.create({
type: search.Type.SAVED_SEARCH,
columns: [{
name: 'internalid'
}, {
name: 'ID'
}, {
name: 'Title'
}, {
name: 'Owner'
}, {
name: 'Access'
}],
filters: typeFilter
});
mySearch.run().each(processRecord);
function processRecord(result) {
var columns = result.columns();
var searchID = result.getValue({
name: 'ID'
});
try {
var loadedSearch = search.load({
id: searchID
});
var searchName = result.getValue({
name: 'Title'
});
var searchType = loadedSearch.searchType;
var searchAccess = loadedSearch.isPublic;
if (searchType == "customer") {
var record = {
SS_ID: result.id,
'Title': searchName,
'Type': searchType,
'Public': searchAccess
};
records.push(record);
}
}
catch (ex) {
// an error occurs when trying to load a search that is actually an update.
}
var x = 0;
return true;
}
});
答案 0 :(得分:2)
您必须将过滤器定义为:
var typeFilter = search.createFilter({
name: 'recordtype',
operator: search.Operator.ANYOF,
values: 'Customer'
});