在netsuite中,我们有几个月(不按顺序排列)。 月数值说:
list_month = [182,183,186,187,188,190,191,192,194,195,196,199,200,201];
我想应用搜索过滤器来获取某些月份内的记录,比如从183到194。
var period = 183;
var period1 = 194;
我使用了“between”和“within”但它没有用“
这是我的过滤器:
filters.push(new nlobjSearchFilter("postingperiod","transaction","within",period,period1));
这只返回值为183.我想要所有这些:183,186,187,188,190,191,192,194。
*请注意,这不是日期,而是月份(从该月的1日到最后日期)
我怎么能得到这个。
由于
答案 0 :(得分:2)
您需要将每个句点指定为单独的过滤器,然后使用.setParens(1)
和.setOr(true)
构建搜索逻辑,如下所示:
var results = nlapiSearchRecord('invoice', null, [
new nlobjSearchFilter('mainline', null, 'is', 'T'),
new nlobjSearchFilter('postingperiod', null, 'within', 122).setLeftParens(1).setOr(true),
new nlobjSearchFilter('postingperiod', null, 'within', 123).setRightParens(1)
], [
new nlobjSearchColumn('internalid', null, 'count')
]);
如果你不总是知道你需要哪些时期,你可以用这样的函数动态生成这些过滤器:
function buildPeriodFilters(periodIds) {
// Return empty array if nothing is passed in so our search doesn't break
if (!periodIds) {
return [];
}
// convert to array if only a single period id is passed in.
periodIds = [].concat(periodIds);
return periodIds.map(function(periodId, index, periodIds) {
var filter = new nlobjSearchFilter('postingperiod', null, 'within', periodId);
// if this is the first periodid, add a left parenthesis
if (index === 0) {
filter = filter.setLeftParens(1);
}
// if this is the last period id, add a right parenthesis, otherwise add an 'or' condition
if (index !== periodIds.length - 1) {
filter = filter.setOr(true);
} else {
filter = filter.setRightParens(1);
}
return filter;
});
}
var dynamicPeriodFilter = buildPeriodFilters([122,123,124]);
var results = nlapiSearchRecord('invoice', null, [
new nlobjSearchFilter('mainline', null, 'is', 'T'),
].concat(dynamicPeriodFilter), [
new nlobjSearchColumn('internalid', null, 'count')
]);