在 Netsuite 中搜索指定月份的过滤器

Search filter in Netsuite for specified months

在 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));

这个returns只有183的值。我想要所有的值:183,186,187,188,190,191,192,194。

*注意这不是日期而是月份(从该月的 1 日到最后一天)

我怎样才能得到这个。

谢谢

您需要将每个时期指定为单独的过滤器,并使用 .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')
]);