``` var orgLocation = itemRs[i]...
# suitescript
r
Copy code
var orgLocation = itemRs[i].getValue({ name : 'inventorylocation'});
                    var orgQuantity = itemRs[i].getValue({ name : 'binonhandcount'});
                    var itemId      = itemRs[i].getValue({ name : 'internalid'});
                    var sourceBin   = itemRs[i].getValue({ name : 'binnumber'});                        
                    
                    var inventoryXfer = record.create({ 
                            type : record.Type.INVENTORY_TRANSFER,
                            isDynamic : true
                        });

                        inventoryXfer.setValue({ fieldId : 'location', value : orgLocation });
                        inventoryXfer.setValue({ fieldId : 'department', value : transferDept});
                        inventoryXfer.setValue({ fieldId : 'transferlocation', value : masterLocationParam });
 
                        inventoryXfer.selectLine({ sublistId : 'inventory', line : 0});
                        inventoryXfer.setCurrentSublistValue({
                            sublistId: 'inventory',
                            fieldId : 'item',
                            value : itemId,
                        });
                        inventoryXfer.setCurrentSublistValue({
                            sublistId: 'inventory',
                            fieldId : 'itemcount',
                            value : orgQuantity,
                        })
                        inventoryXfer.setCurrentSublistValue({
                            sublistId: 'inventory',
                            fieldId : 'quantityonhand',
                            value : orgQuantity,
                        })
                        inventoryXfer.setCurrentSublistValue({
                            sublistId: 'inventory',
                            fieldId : 'tobins',
                            value : bin,
                        })
                        inventoryXfer.commitLine({ sublistId: 'inventory'});
                        inventoryXfer.save();
a
This might be wrong but you’re creating a new record, so I think there is no existing line at line index 0. Try using
inventoryXfer.selectNewLine({sublistId:'YourID'})
perhaps?
r
I tried that, I got the same error 🙃
b
you can try using static mode and not setting fields that you cant in the ui like quantityonhand
in fact, i think you are supposed to set adjustqtyby instead of itemcount
d
I used to work on Transfer Order creation previously and finally managed to make it work in dynamic mode. The key was to create all inventoryassignment inside inventory before saving the inventory. If you need, I can share my code.
r
@Dmitry Masanov If you wouldn't mind that would be great!
I haven't tried the adjustment just yet.
d
Copy code
function copyInventoryDetails(sourceRecord: record.ClientCurrentRecord, targetRecord: record.ClientCurrentRecord) {
    for (let itemLineNumber = 0; itemLineNumber < sourceRecord.getLineCount({sublistId: 'item'}); itemLineNumber++){
        // newScriptResult.logs.push(`Working with ITEM line ${itemLineNumber}`);
        sourceRecord.selectLine({sublistId: 'item', line: itemLineNumber});
        targetRecord.selectLine({sublistId: 'item', line: itemLineNumber});
        const oldInventoryDetails = sourceRecord.getCurrentSublistSubrecord({
            sublistId: 'item',
            fieldId: 'inventorydetail',
        });
        const newInventoryDetails = targetRecord.getCurrentSublistSubrecord({sublistId: 'item', fieldId: 'inventorydetail'});
        const serialNumbersInOldRecord = oldInventoryDetails.getLineCount({sublistId: 'inventoryassignment'});

        // const serialNumbersArray = ['ACCC8EB54B87', 'ACCC8EB5578F'];

        for (let serialNumberNumber = 0; serialNumberNumber < serialNumbersInOldRecord; serialNumberNumber++) {
            oldInventoryDetails.selectLine({sublistId: 'inventoryassignment', line: serialNumberNumber});

            const oldQuantity = oldInventoryDetails.getCurrentSublistValue({sublistId: 'inventoryassignment', fieldId: 'quantity'});
            const oldSerialNumber = oldInventoryDetails.getCurrentSublistText({sublistId: 'inventoryassignment', fieldId: 'issueinventorynumber'});
            console.log(`Old serial number is "${oldSerialNumber}" with quantity of ${oldQuantity}`);
            // const oldSerialNumber = serialNumbersArray[serialNumberNumber];
                newInventoryDetails.selectNewLine({sublistId: 'inventoryassignment'});

            newInventoryDetails.setCurrentSublistValue({
                sublistId: 'inventoryassignment',
                fieldId: 'quantity',
                value: oldQuantity
            });

            newInventoryDetails.setCurrentSublistValue({
                sublistId: 'inventoryassignment',
                fieldId: 'receiptinventorynumber',
                value: oldSerialNumber,
            });
            console.log(`Commiting serial number ${serialNumberNumber}: ${oldSerialNumber}`);
            newInventoryDetails.commitLine({
                sublistId: 'inventoryassignment',
            });
            console.log(`Successfully commited serial number ${oldSerialNumber} in line ${itemLineNumber}, position ${serialNumberNumber}`);
        }

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

    }

}
so, source record is the record where we have some inventory details, in target record inventory details are empty. The function copies all serial numbers from source record to target record
Both records are loaded in dynamic mode
r
@Dmitry Masanov Thank you, I don't believe that is the case for me as the account doesn't have Advanced Inventory Management enabled. Only when that feature is enabled will I need to use InventoryDetail
@battk Looks like adjustbyqty didn't work either