I’m new to suitescript, I’ve got a schedule script to Transform a PO to Item Receipt. Which needs to create a record on Subrecord on inventorydetail sub record, I get “USER_ERROR”,”message”:”The total inventory detail quantity must be 1.” – Not sure what I have done wrong. If i use the same code for a non stock and remove the sub record insert line and coding it works
var csvPOId = 73586;
var csvPOLocationId = 1;
var csvPOQty = 1;
var csvBinId = '';
var csvSerialLot = '';
var csvInvQty = 1;
//
try {
var itemReceiptRec = record.transform({
fromType: record.Type.PURCHASE_ORDER,
fromId: csvPOId,
toType: record.Type.ITEM_RECEIPT,
isDynamic: false
});
} catch (e) {
log.error({
title: e.name,
details: e.message
});
}
// Get count - Sublist Lines
var count = itemReceiptRec.getLineCount({
sublistId: 'item'
});
for (var i=0; i < count; i++) {
// Item Sub List - Mark as Received
var itemReceived = itemReceiptRec.getSublistValue({
sublistId: 'item',
fieldId: 'itemreceive',
line: i
});
// Location
itemReceiptRec.setSublistValue({
sublistId: 'item',
fieldId: 'location',
value: csvPOLocationId, // '11 - Central Main Warehouse',
line: i
});
// Quantity
itemReceiptRec.setSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: csvPOQty,
line: i
});
// Inventory Detail Sub Record [inventorydetail]
var subrec = itemReceiptRec.getSublistSubrecord({
sublistId: 'item',
line: i,
fieldId: 'inventorydetail'
});
subrec.insertLine({
sublistId: 'inventoryassignment',
line: 0
});
// // Quantity - Mandatory
subrec.setSublistValue({
sublistId: 'inventoryassignment',
fieldId: 'quantity',
line: 0,
value: csvInvQty
});
var itemRecID = itemReceiptRec.save({
enableSourceing: true
});
log.debug({
title: 'New Item Receipt Record',
details: 'Internal ID ' + itemRecID
});