Suitescript 1:删除添加的订单项时出错

Suitescript 1: Error on removing added line items

总体而言,我对 Netsuite 和 Suitescript 非常陌生。我有一个 suitelet 和一个按钮,用于在销售订单上添加和计算折扣列表(我正在获取小计折扣项目),目前正在尝试删除折扣行并重新添加它们,但我收到错误 "This line cannot be deleted, because it is referred to by other records. Before removing this line, remove any discount or markup lines applied to it."

我的代码是这样的:

            for (var i = 1; i <= recordLoad.getLineItemCount('item'); i++) {
                var x = recordLoad.findLineItemValue('item', 'item', subTotalRecord);
                if (x > 0) {
                    recordLoad.removeLineItem('item', x);
                }
            }

            //Remove all the discount lines
            var discountItemInternalIds = [422, 420, 637, 632, 418, 636, 640, 421, 423, 628, 638, 417];
            discountItemInternalIds.forEach(function(discountInternalId) {
                var x = recordLoad.findLineItemValue('item', 'item', discountInternalId);
                if (x > 0) {
                    recordLoad.removeLineItem('item', x)
                }
            });

有办法吗?我才开始学习 Suitescript 才 2 个月。

If you are using suite script 2.0
Then try Below Code
// To get the Line Number
var lineNumber = objRecord.findSublistLineWithValue({
    sublistId: 'item',
    fieldId: 'item',
    value: 233
});

//
var lineNum = objRecord.selectLine({
    sublistId: 'item',
    line: 3
});


var hasSubrecord = objRecord.hasCurrentSublistSubrecord({
    sublistId: 'item',
    fieldId: 'item'
});

if(hasSubrecord ){
objRecord.removeCurrentSublistSubrecord({
    sublistId: 'item',
    fieldId: 'item'
});

objRecord.commitLine({
    sublistId: 'item'
});

}

在我了不起的上司的帮助下,我设法做到了呵呵。

我们所做的是获取折扣和小计折扣的项目类型,并确保先删除折扣,然后再删除小计。

                for(var x = lineCount; x > 0; x--){
                // var lineType = recordLoad.getLineItemValue('item','itemtype',x).toLowerCase();
                if(recordLoad.getLineItemValue('item','itemtype',x) == 'Discount'){     
                    recordLoad.removeLineItem('item',x);
                }
            }
            // nlapiLogExecution('ERROR', 'lineType', lineType);

            for(var x = lineCount; x > 0; x--){
                // var lineType = recordLoad.getLineItemValue('item','itemtype',x).toLowerCase();
                if(recordLoad.getLineItemValue('item','itemtype',x) == 'Subtotal'){
                    recordLoad.removeLineItem('item',x);
                }
            }