如何在NetSuite中将用户记录与已保存的搜索相匹配?

时间:2017-08-17 20:52:37

标签: javascript arrays javascript-objects netsuite

我正在尝试通过加载搜索并将结果推送到数组来创建对象数组:

var searchArr = [];

    var dfaSearch = search.load({
        id: 'id_of_search'
    });

    var runSearch = dfaSearch.run().getRange({
        start: 0,
        end: 100            
    });
    for (x=0; x<runSearch.length;x++) {
        var engine = runSearch[x].getValue({
            name: 'id_of_department_column'
        })
        var approver = runSearch[x].getValue({
            name: 'id_of_approver_column'
        });
        var lowT = runSearch[x].getValue({
            name: 'id_of_lowerapproval_column'
        });
        var upT = runSearch[x].getValue({
            name: 'id_of_upperapproval_column'
        });

       var  searchCriteria = {
          engine : engine,
          approver: approver,
          lowT : lowT,
          upT : upT 
       };

       searchArr.push(searchCriteria);
    }

我还有一些代码可以加载当前用户的记录以获取内部ID等。但是,当尝试使用静态ID进行测试时,我会继续接收:

TypeError: Cannot find function find in object.

以下是代码的其余部分:

function findApprover(approverInfo) {
     return approverInfo.engine === '26';
}
var approverInfo = searchArr.find(findApprover);
log.debug({
   title : 'Current User Approver ID',
   details : approverInfo
});

}

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

find方法在ES2015中引入,NetSuite不支持。您可以尝试使用像underscore这样的第三方库,其中包含用于ES2015方法的polyfill,例如find

function findApprover(approverInfo) {
     return approverInfo.engine === '26';
}

var approverInfo = _.find(searchArr, findApprover);

log.debug({
   title : 'Current User Approver ID',
   details : approverInfo
});

或者以不同的方式搜索审批者,例如,使用for循环:

function findApprover(array, key, value) {
    for (var i = 0; i < array.length; i++) {
        if (array[i][key] === value) {
            return array[i];
        }
    }
    return null;
}

var approverInfo = findApprover(searchArr, 'engine', '26');

log.debug({
   title : 'Current User Approver ID',
   details : approverInfo
});