使用 Suitescript 仅使用项目的外部 ID 在 Netsuite 中创建发票

Use ONLY the external id of an item to create an invoice in Netsuite using Suitescript

是否可以使用项目的外部 ID 而不是使用 Restlet 的内部 ID 创建发票?我可以像这样在 Postman 中完成此操作:

 "item": {
        "items": [

            { 
                "amount": 120.0,
                "item": {
                    "externalid": "12878"
                },
                 "taxCode": {                    
                    "id": "13"                    
                }
            }
        ]
    } 

但是当我尝试在 Restlet 中进行相同设置时,它会抛出错误。

var currentItem = items[i];
record.selectNewLineItem('item');
record.setCurrentLineItemValue('item', 'externalid', currentItem["exId"]);
record.setCurrentLineItemValue('item', 'quantity', currentItem["quantity"]);
record.setCurrentLineItemValue('item', 'rate', currentItem["rate"]);
record.setCurrentLineItemValue('item', 'taxcode', currentItem["taxcode"]);
record.commitLineItem('item');
{"error":{"code":"INVALID_KEY_OR_REF","message":"Invalid item reference key 12878 for subsidiary 1."}}

您需要做的是通过外部 ID 搜索项目。

var extIds = items.map(function(it){ return it.exId});
var items = nlapiSearchRecord('item', null, [
    new nlobjSearchFilter('externalid', null, 'anyof', extIds)
], [
    new nlobjSearchColumn('externalid')
]);
// check for null return and throw error
var extIdMap = {};
items.forEach(function(ref){
    extIdMap[ref.getValue('externalid')] = ref.getId();
});

//then instead of record.setCurrentLineItemValue('item', 'externalid', currentItem["exId"]);
record.setCurrentLineItemValue('item', 'item', extIdMap[currentItem["exId"]]);