如何在 Netsuite 中创建保存的搜索,方法是在 SuiteScript 2.0 中使用左外部联接连接两条记录

How to create saved search in netsuite by joining two records using left outer join in SuiteScript 2.0

本文关键字:外部 连接 两条 记录 保存 创建 Netsuite 搜索 SuiteScript 方法      更新时间:2023-09-26

我想通过在"SuiteScript 2.0 版本"中使用左外部连接连接两个记录来创建搜索

第一条记录是标准记录(

发票),第二条记录是自定义记录(合同),两条记录都具有公共字段,即:类别和交易类型,所有者。

发票记录字段是交易列字段(类别、交易类型、所有者)合同记录字段是自定义字段(类,交易,所有者)

我已经创建了发票记录的搜索,

并根据发票记录的搜索结果,我在合同记录上创建了搜索。 我的代码给出了正确的结果,但问题是"是否可以在 SuiteScript 2.0 版本中使用左外部联接创建对两个不同记录的搜索?

 //Create Search on Standard Invoice Record
            var mySearch = search.create({
                type: 'invoice',
                columns: ['internalId', 'item', 'line', 'custcol_class', 'custcol_transaction_type', 'custcol_owner', 'amount'],
                filters: ['trandate', 'after', '12/15/2015']
            });
            //Executing the First 100 records on the search result
            var searchResult = mySearch.run().getRange(0, 100);
            log.debug('Search Length', searchResult.length);
            for (var i = 0; i < searchResult.length; i++) {
                var lineId = searchResult[i].getValue({
                    name: 'line'
                });
                var item = searchResult[i].getValue({
                    name: 'item'
                });
                var contractClass = searchResult[i].getValue({
                    name: 'custcol_class'
                });
                var transactionType = searchResult[i].getValue({
                    name: 'custcol_transaction_type'
                });
                var owner = searchResult[i].getValue({
                    name: 'custcol_owner'
                });
                var invoice_id = searchResult[i].getValue({
                    name: 'internalId'
                });
                var invoice_amt = searchResult[i].getValue({
                    name: 'amount'
                });
                log.debug('Values', 'contractClass:' + contractClass + '-transactionType:' + transactionType + '-owner:' + owner);
                if (contractClass != '' && owner != '' && transactionType != '') {
                    log.debug('create commision', 'item' + item + '-lineId:' + lineId + '-contractClass:' + contractClass + '-transactionType:' + transactionType + '-owner:' + owner);
                    createCommission(contractClass, transactionType, owner, invoice_id, invoice_amt);
                }

            }

        }
        function createCommission(contractClass, transactionType, owner, invoiceId, invoice_amt) {
            log.debug('Entry', 'createCommission Initiated');
            log.debug('invoice amount..', invoice_amt);
            //Creating search on Custom Record Contract
            var mySearch = search.create({
                type: 'customrecord_contract',
                columns: ['internalId', 'custrecord_rec_class', 'custrecord_vendor_fees_formula'],
                filters: [
                    ['custrecord_rec_class', 'anyof', contractClass], 'AND', ['custrecor_rec_transaction_type', 'anyof', transactionType], 'AND', ['custrecord__rec_owner', 'anyof', owner], 'AND', ['custrecord__vendor_fees_formula', 'anyof', INRAM_RS_V1]
                ]
            });
}

提前致谢

不幸的是,

NetSuite目前无法做到这一点。

您将不得不满足于编写一个函数,该函数接收两组结果并相应地组合它们。如果您使用任何数组实用程序库(如 lodash),则可以使用 _.groupBy 之类的东西来简化组合。