Netsuite 中指定月份的搜索过滤器 [英] Search filter in Netsuite for specified months

查看:44
本文介绍了Netsuite 中指定月份的搜索过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 netsuite 中,我们有几个月的时间(不按顺序排列).月值说:

In netsuite we have months (Not in serial order). months values are say :

list_month = [182,183,186,187,188,190,191,192,194,195,196,199,200,201];

我想应用搜索过滤器来获取特定月份内的记录,比如从 183 到 194.

I want to apply search filter to get records within certain months say from 183 to 194.

var period = 183;
var period1 = 194;

我使用了介于"和内部",但没有用'

I used the "between" and "within" but it did not work'

这是我的过滤器:

filters.push(new nlobjSearchFilter("postingperiod","transaction","within",period,period1));

这仅返回 183 的值.我想要所有这些值:183,186,187,188,190,191,192,194.

this returns only the values of 183. I want all of them : 183,186,187,188,190,191,192,194.

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

*Note this are not dates but months (starting from 1 to last date of that month)

我怎样才能得到这个.

谢谢

推荐答案

您需要将每个期间指定为单独的过滤器并使用 .setParens(1).setOr(true) 像这样构建搜索逻辑:

You would need to specify each period as a separate filter and use .setParens(1) and .setOr(true) to build out the logic of your search like this:

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')
]);

如果您不总是知道需要哪些时间段,您可以使用如下函数动态生成这些过滤器:

If you don't always know which periods you'll need, you can generate these filters dynamically with a function like this:

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')
]);

这篇关于Netsuite 中指定月份的搜索过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆