【问题标题】:Search filter in Netsuite for specified months在 Netsuite 中搜索指定月份的过滤器
【发布时间】:2016-12-07 16:15:45
【问题描述】:

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

我使用了“之间”和“内部”,但它不起作用'

这是我的过滤器:

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

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

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

我怎样才能得到这个。

谢谢

【问题讨论】:

    标签: netsuite suitescript


    【解决方案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')
    ]);
    

    【讨论】:

    • 这有效,但仅适用于 to 和 from 月份。它跳过了我想要的中间月份。月份的数组是:list_month = [182,183,186,187,188,190,191,192,194,195,196,199,200,201];假设我希望它位于 183 和 194。所以过滤器应该应用于 183,186,187,188,190,191,192,194 目前它只应用于 183 和 19
    • *和 194 这就是我正在做的事情:var period = 183; var period1 = 194; filters.push(new nlobjSearchFilter("postingperiod","transaction","between",period).setLeftParens(1).setOr(true)); filters.push(new nlobjSearchFilter("postingperiod","transaction","between",period1).setRightParens(1)); 我试过了:filters.push(new nlobjSearchFilter("postingperiod","transaction","between",list_month[period]).setLeftParens(1).setOr(true)); filters.push(new nlobjSearchFilter("postingperiod","transaction","between",list_month[period1]).setRightParens(1)); 但这不起作用。
    • 尝试在过滤器定义中将 'between' 更改为 'within'。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-19
    • 1970-01-01
    • 1970-01-01
    • 2014-08-13
    • 2017-07-01
    • 2012-12-14
    • 1970-01-01
    相关资源
    最近更新 更多