我一直在尝试创建一个 Suitescript 来履行转移订单,但没有成功。我不确定是否需要同时创建商品履行和商品收据?我似乎到处都得到不同的答案。
我需要脚本来履行转移订单上每个项目的数量并将其状态更新为“已收到”。
到目前为止,我拥有的脚本能够创建项目履行。这更新了转储订单项目的“完整”数量,但未更新履行数量。状态也保持在“待履行”。
尝试创建商品收据时出现以下错误:
任何帮助将不胜感激。
这是我迄今为止在脚本调试器中测试的内容:
require(['N/record', 'N/search', 'N/log'], function(record, search, log) {
try {
var transferOrderId = 533010;
var transferOrder = record.load({
type: record.Type.TRANSFER_ORDER,
id: transferOrderId
});
var transferOrderType = transferOrder.type;
// Ensure the record being processed is a Transfer Order
if (transferOrderType !== 'transferorder') {
log.debug('Not a Transfer Order', 'Skipping processing.');
return;
}
// ********** Item Fulfillment Logic **********
// Check if an Item Fulfillment already exists for the Transfer Order
var fulfillmentSearch = search.create({
type: record.Type.ITEM_FULFILLMENT,
filters: [
['createdfrom', 'is', transferOrderId]
],
columns: ['internalid']
});
var fulfillmentResults = fulfillmentSearch.run().getRange({ start: 0, end: 1 });
if (fulfillmentResults && fulfillmentResults.length > 0) {
log.debug('Item Fulfillment Exists', 'Item Fulfillment already exists for Transfer Order ID: ' + transferOrderId);
} else {
// Transform the Transfer Order to an Item Fulfillment
var itemFulfillment = record.transform({
fromType: record.Type.TRANSFER_ORDER,
fromId: transferOrderId,
toType: record.Type.ITEM_FULFILLMENT,
isDynamic: true
});
// Iterate over the lines to ensure quantities are properly set
var fulfillmentLineCount = itemFulfillment.getLineCount({ sublistId: 'item' });
for (var i = 0; i < fulfillmentLineCount; i++) {
itemFulfillment.selectLine({ sublistId: 'item', line: i });
// Set the quantity to fulfill as the quantity remaining to be fulfilled
var quantityToFulfill = itemFulfillment.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantityremaining'
});
itemFulfillment.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: quantityToFulfill
});
itemFulfillment.commitLine({ sublistId: 'item' });
}
// Save the Item Fulfillment
var itemFulfillmentId = itemFulfillment.save();
log.debug('Item Fulfillment Created', 'Item Fulfillment ID: ' + itemFulfillmentId);
}
// ********** Item Receipt Logic **********
// Check if an Item Receipt already exists for the Transfer Order
var receiptSearch = search.create({
type: record.Type.ITEM_RECEIPT,
filters: [
['createdfrom', 'is', transferOrderId]
],
columns: ['internalid']
});
var receiptResults = receiptSearch.run().getRange({ start: 0, end: 1 });
if (receiptResults && receiptResults.length > 0) {
log.debug('Item Receipt Exists', 'Item Receipt already exists for Transfer Order ID: ' + transferOrderId);
} else {
// Transform the Transfer Order to an Item Receipt
var itemReceipt = record.transform({
fromType: record.Type.TRANSFER_ORDER,
fromId: transferOrderId,
toType: record.Type.ITEM_RECEIPT,
isDynamic: true
});
// Iterate over the lines to ensure quantities are properly set
var receiptLineCount = itemReceipt.getLineCount({ sublistId: 'item' });
for (var i = 0; i < receiptLineCount; i++) {
itemReceipt.selectLine({ sublistId: 'item', line: i });
// Set the quantity to receive as the quantity remaining to be received
var quantityRemaining = itemReceipt.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantityremaining'
});
itemReceipt.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: quantityRemaining
});
itemReceipt.commitLine({ sublistId: 'item' });
}
// Save the Item Receipt
var itemReceiptId = itemReceipt.save();
log.debug('Item Receipt Created', 'Item Receipt ID: ' + itemReceiptId);
}
} catch (e) {
log.error('Error Processing Transfer Order', e);
}
});
总的来说,你的想法是正确的。使用转移订单时,您需要先履行它,然后才能接收它。这就是为什么您在创建收据时收到无效参考错误的原因。
至于履行,您说您没有看到 TO 上的项目已履行。您的帐户的配送状态是否处于“提货-包装-发货”状态?我认为在您的履行转换中,您只需将状态设置为已发货。然后按原样画线,然后保存。看看是否有帮助。