我目前正在尝试在采购订单上制作一个按钮,这将允许用户轻松更新批次编号库存项目的购买价格。该按钮将使用预期参数调用以下函数。这些值都是预期值并输出预期值,但 LNIT 记录上的值似乎没有差异。
function updatePurchasePrice(itemID, vendor, purchasePrice) {
log.debug("Update Purchase Price", "Started");
try {
// Load the item record
var itemRecord = record.load({
type: record.Type.LOT_NUMBERED_INVENTORY_ITEM,
id: itemID,
isDynamic: true
});
// Get the line count for the itemvendor sublist
var lineCount = itemRecord.getLineCount({
sublistId: 'itemvendor'
});
// Iterate through the itemvendor sublist
for (var i = 0; i < lineCount; i++) {
log.debug("Line Number", i);
// Get the vendor at the current line
itemRecord.selectLine({
sublistId: 'itemvendor',
line: i
});
var currentVendor = itemRecord.getCurrentSublistValue({
sublistId: 'itemvendor',
fieldId: 'vendor'
});
// Check if this is the vendor we want to update
if (currentVendor == vendor) {
log.debug("Vendor Found", vendor);
itemRecord.setCurrentSublistValue({
sublistId: 'itemvendor',
fieldId: 'purchaseprice',
value: purchasePrice
});
log.debug("After setting purchaseprice", purchasePrice);
itemRecord.setCurrentSublistValue({
sublistId: 'itemvendor',
fieldId: 'vendorprices',
value: 'USA: ' + purchasePrice
});
log.debug("After setting vendorprices", 'USA: ' + purchasePrice);
itemRecord.commitLine({
sublistId: 'itemvendor'
});
log.debug("Committed line", i);
// Save the changes to the record
var saveId = itemRecord.save({
enableSourcing: false,
ignoreMandatoryFields: true
});
log.debug("Record Saved", "Record ID: " + saveId);
break; // Exit the loop once we've updated the correct vendor
}
}
} catch (e) {
log.error({
title: 'Error updating purchase price',
details: e.toString()
});
}
}
帮助屏幕截图:下面的屏幕截图显示了我正在尝试编辑的记录。可能相关的信息:通过用户界面编辑购买价格时,会出现一个弹出窗口,让我选择货币和购买价格。
我想通了。您实际上必须删除子列表行并创建一个新行。我刚刚复制了所有字段。