I’m trying to add lines to a newly created dynamic...
# suitescript
t
I’m trying to add lines to a newly created dynamic Item Receipt record using the following code, but I keep getting this error message when I try to selectNewLine:
Copy code
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.
Copy code
for (let i = 0; i < purchaseOrderRecord.getLineCount('item'); i++) {
    log.debug('start loop');
    itemReceiptRecord.selectNewLine('item');

    log.debug('item')
    itemReceiptRecord.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'item',
        value: purchaseOrderRecord.getSublistValue({
            sublistId: 'item',
            fieldId: 'item',
            line: i
        })
    })
    log.debug('quantity')
    itemReceiptRecord.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'quantity',
        value: purchaseOrderRecord.getSublistValue({
            sublistId: 'item',
            fieldId: 'quantity',
            line: i
        })
    })
    log.debug('location')
    itemReceiptRecord.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'location',
        value: purchaseOrderRecord.getSublistValue({
            sublistId: 'item',
            fieldId: 'location',
            line: i
        })
    })

    itemReceiptRecord.commitLine('item');
}
Anyone have any ideas what could be causing this?