Jo
04/09/2020, 1:02 PMbattk
04/09/2020, 1:22 PMbattk
04/09/2020, 1:36 PM// consider if a before submit user event is appropiate
// loading the current record to make changes basically doubles save time
function userEventAfterSubmit(type) {
var recLoad = nlapiLoadRecord(nlapiGetRecordType(), nlapiGetRecordId());
var itemcnt = recLoad.getLineItemCount("item");
var lastInventoryItemLine;
for (var i = 1; i <= itemcnt; i++) {
var itemType = recLoad.getLineItemValue("item", "itemtype", i);
var itemId = recLoad.getLineItemValue("item", "item", i);
// to be clear, this code fails miserably if there are items that aren't
// inventory items
if (itemType === "InvtPart") {
lastInventoryItemLine = i;
} else if (itemId == "83" && lastInventoryItemLine) {
// you might want to make this a sum
// you might also want to handle the case where the first line is a discount
// amount is much safer than rate
recLoad.setLineItemValue(
"item",
"custcol_row_discount",
lastInventoryItemLine,
recLoad.getLineItemValue("item", "amount", i)
);
}
}
nlapiSubmitRecord(recLoad, true);
}
battk
04/09/2020, 1:59 PMNElliott
04/09/2020, 2:10 PMJo
04/09/2020, 2:32 PM