** SuiteScript 2.0 **在客户端脚本中创建搜索对象时出错

时间:2016-11-11 01:13:48

标签: netsuite suitescript

searchResultSet.columns.length - >未定义....

此代码中缺少什么?

function pageInit(scriptContext){

    try{  
    var currentRecord = scriptContext.currentRecord;
    var searchObj = search.load({
       id:'customsearchvc_bt_duplicate_vendor_list'
    });

    var searchResultSet=searchObj.run();
    var noOfDupVendors = searchResultSet.length;  

    log.debug({details: "there are "+searchResultSet.columns.length+" duplicate vendors"});

    currentRecord.setText({
        fieldId: 'custrecordvc_merge_vendor_total_unique_v',
        text: noOfDupVendors
    });

    }catch(e){
        log.error("error at getinputdata stage","error detail is :"+e.message);
    }

1 个答案:

答案 0 :(得分:2)

searchResultSet对象上没有length属性。该集合实际 包含结果(我知道,它很奇怪)您需要遍历结果以使它们相加。在你的情况下,你可以匆匆忙忙地离开"它总是小于1000"溶液:

var searchResults = searchResultSet.getResults({
    start: 0, 
    end: 1000
});

var noOfDupVendors = searchResults.length

无限结果的解决方案可能如下所示:(未经测试):

var searchResults;
var noOfDupVendors = 0;

do{
    searchResults = searchResultSet.getResults({
        start: noOfDupVendors,
        end: noOfDupVendors+1000
    });
    noOfDupVendors += searchResults.length
}while(searchResults.length == 1000);

另一种(也是未经测试的)紧凑方式,如果你可以指望4000或更少的结果将是:

var noOfDupVendors = 0;

searchResultSet.each(function(result){noOfDupVendors++; return true;})