I'm in the process of creating a module to handle multi-PO consolidated shipments (fx imports) and writing a script to receive multiple POs with landed costs per line.
I'm using SuiteScript API 1.0
However, when I create the Item Receipt record (and include the PO# in the createdfrom field to create the link from IR to PO, during the process of copying the PO lines to the IR lines, I'm getting constant SSS_INVALID_SUBLIST_OPERATION errors.
The code in question is below:
// ** set body fields
receiptRec.setFieldValue('location',purchRec.getFieldValue('location'));
receiptRec.setFieldValue('entity',purchRec.getFieldValue('entity'));
receiptRec.setFieldValue('createdfrom',purchRec.getFieldValue('internalid'));
receiptRec.setFieldValue('currency',purchRec.getFieldValue('currency'));
receiptRec.setFieldValue('exchangerate',purchRec.getFieldValue('exchangerate'));
receiptRec.setFieldValue('isbasecurrency',purchRec.getFieldValue('isbasecurrency'));
receiptRec.setFieldValue('exchangerate',purchRec.getFieldValue('exchangerate'));
receiptRec.setFieldValue('landedcostperline','T');
log ('Receipt Record:'); log( receiptRec );
// ** copy item lines
var POlines = purchRec.getLineItemCount('item');
for ( line=1 ; line<=POlines; line++) {
var fulfill = purchRec.getLineItemValue('item','fulfillable',line); log('Fulfill?? '+fulfill)
if (fulfill == 'T') {
log('Fill From PO Line #'+line);
receiptRec.selectNewLineItem('item'); log('Debug 1');
receiptRec.setCurrentLineItemValue('item','item',purchRec.getLineItemValue('item','item',line)); log('Debug 2');
receiptRec.setCurrentLineItemValue('item','itemreceive','T',line); log('Debug 3');
receiptRec.setCurrentLineItemValue('item','quantity',purchRec.getLineItemValue('item','quantity',line)); log('Debug 4');
receiptRec.setCurrentLineItemValue('item','rate',purchRec.getLineItemValue('item','rate',line)); log('Debug 5');
receiptRec.setCurrentLineItemValue('item','taxcode',purchRec.getLineItemValue('item','taxcode',line)); log('Debug 6');
receiptRec.setCurrentLineItemValue('item','units',purchRec.getLineItemValue('item','units',line)); log('Debug 7');
receiptRec.commitLineItem('item'); log('Debug 8');
}
}
The error is triggering at the selectNewLineItem('item') point.
receiptRec is the newly created itemreceipt record.
purchRec is the existing purchase order record.
What am I missing here?