I am trying to script a work order completion in Netsuite but it is returning
"SSS_INVALID_SUBLIST_OPERATION - 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."
Here is my code.
function preRequest(datain){
//var id = 514752;
//var sn = KQ0006608;
var record = nlapiTransformRecord('workorder', datain.id, 'workordercompletion');
record.setFieldValue('quantity', 1);
var subrecord2=record.createSubrecord( 'inventorydetail');
subrecord2.selectNewLineItem( 'inventoryassignment' );
//subrecord2.selectLineItem('inventoryassignment', 1);
subrecord2.setCurrentLineItemValue('inventoryassignment', 'receiptinventorynumber', datain.sn);
subrecord2.setCurrentLineItemValue('inventoryassignment', 'binnumber', 25);
subrecord2.setCurrentLineItemValue('inventoryassignment', 'quantity', 1);
subrecord2.commitLineItem('inventoryassignment');
subrecord2.commit();
record.commitLineItem('inventorydetail');
nlapiSubmitRecord(record);
}
I have in good faith gone through their documentation and know what the error is and what might be causing it but I don't know how to fix the code so it will submit the record. Any help would be awesome!
EDIT: Another clue is that Netsuite is treating the Quantity to Build field ('quantity' in my code) as a sublist. This is the root cause of the error. Fixing this will fix my code. Just not sure how.
EDIT: See Work Order Completion UI page for reference.Work Order Completion UI Page