Search code examples
netsuiterecordsublist

Error when trying to removeLine on item_fulfillment


I am trying to transform a sales order to an Item fulfillment and remove some item lines but I get the following error:

name : SSS_INVALID_SUBLIST_OPERATION

message: You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist

My code:

// Transform the record 
var objRecord = record.transform({
                    fromType: record.Type.SALES_ORDER,
                    fromId: soid,
                    toType: record.Type.ITEM_FULFILLMENT,
                    isDynamic: true,
                });

// Remove second location 
var linecount = objRecord.getLineCount({sublistId: 'item'});
for (var i = 0; i < linecount; i++) {
   objRecord.selectLine({sublistId: "item",line: i});
   var locationid = objRecord.getCurrentSublistValue({sublistId: 'item',fieldId: 'location'});
   if (locationid != 15)
      objRecord.removeLine({sublistId: 'item',line: i});
}

There are 10 lines in the Sales order. Only 1 has some quantity allocated and ready to be fulfilled, maybe when I try to delete it that causes the error? But it seems the errors come from something else.

I tried to set: isDynamic: false (same error)


Solution

  • The problem was not due to the index of the lines but to the operation on the record. On an item fulfillment the function objRecord.removeLine is not available. To remove rows from the fulfillment item it we have to use :

    objRecord.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'itemreceive',
        value : false
    })