I am transforming a PO to vendor bill. It works fi...
# suitescript
n
I am transforming a PO to vendor bill. It works fine when I bill the complete quantity. But when I partially bill the PO, I am getting the error "The total inventory detail quantity must be 40." The quantity on the line and inventory detail is 40. I have checked using getSublistValue and have used dynamic mode as well. Both report the quantity of 40. SuiteAnswers suggest that this expected behavior (??) and that I need to change the IR quantity first. However, I can do this via UI though.
b
what does the code look like
n
Here is the code:
Copy code
var dataMap= getDataMap(params);
var vendorBillRec = record.transform({
    fromType: record.Type.PURCHASE_ORDER,
    fromId: params.purchaseOrderId,
    toType: record.Type.VENDOR_BILL,
});
vendorBillRec.setValue({fieldId: 'tranid', value: params.vendorBillReferenceNumber});

lines = vendorBillRec.getLineCount({sublistId: 'item'});

var i = lines - 1;
while (i >= 0) {
    var purchaseContract = vendorBillRec.getSublistValue({sublistId: 'item', fieldId: 'custcol_pocontract_ref', line: i});
    if (!purchaseContract) {
       vendorBillRec.removeLine({sublistId: 'item', line: i});
    }
    i = i - 1;
}

var lines = vendorBillRec.getLineCount({sublistId: 'item'});

		for (var i = 0; i < lines; i++) {
			var item = vendorBillRec.getSublistValue({sublistId: 'item', fieldId: 'item', line: i});
			var lotNumber = vendorBillRec.getSublistText({sublistId: 'item', fieldId: 'custcol_lot_no', line: i}) ||
					vendorBillRec.getSublistValue({sublistId: 'item', fieldId: 'custcol_lot_no', line: i});
			var consignmentId = vendorBillRec.getSublistText({sublistId: 'item', fieldId: 'custcol_consignement_id', line: i}) ||
					vendorBillRec.getSublistValue({sublistId: 'item', fieldId: 'custcol_consignement_id', line: i});

			var key = item + '_' + lotNumber + '_' + consignmentId;

			vendorBillRec.setSublistValue({sublistId: 'item', fieldId: 'quantity', line: i, value: dataMap[key].qty});
			vendorBillRec.setSublistValue({sublistId: 'item', fieldId: 'rate', line: i, value: dataMap[key].rate});

			var inventoryDetail = vendorBillRec.getSublistSubrecord({
				sublistId: 'item',
				fieldId: 'inventorydetail',
				line: i
			});

			inventoryDetail.setSublistValue({
				sublistId: 'inventoryassignment',
				fieldId: 'quantity',
				line: 0,
				value: parseFloat(dataMap[key].qty)
			});
		}
var vendorBillId = vendorBillRec.save({enableSourcing: true, ignoreMandatoryFields: true});
b
code looks fine if your purchase orders are simple with only 1 inventoryassignment line
else you may want to try hardcoding your variables to make sure dataMap is actually working
n
I have hardcoded quantity. Got the same error. Yes, PO has only 1 inventory assignment line for each.
b
your code should work in a simple case, so start with a purchase order that has one line, dont remove any line, dont make loops, just set the fields on the one line
if that still doesnt work, you want to check for other scripts (or less likely workflows) deployed to the vendor bill
n
It works when I bill full quantity. Partial billing is causing this error. I disabled other scripts and WFs. Same error.
b
creating partial billing for one line works perfectly fine in all accounts ive tried
so you want to figure out what you are doing differently, which was my advice to start with something more simple
n
One line VB is also not working if I use lesser quantity than on the line. Same error. Otherwise, if I bill the full qty of the line, it is created for one line.
b
what did your most simple code look like
n
Partial bill worked when I modified the item receipt lines quantity to be the same as the VB. Same code worked without any issues.
and about the code, I didn't change it. Just removed the lines and leaving 1.
I have handled this problem using the before submit event on vendor bill.