Я пытаюсь создать возмещение клиенту из разрешения на возврат и кредит-ноты. Сообщение об ошибке звучит так, будто у меня нет позиций, хотя есть как минимум 1.
Это код, который я использую для создания возврата клиента:
var returnAuth = nlapiLoadRecord("returnauthorization", returnAuthId);
var status = returnAuth.getFieldValue("status");
nlapiLogExecution("debug", "status", status);
if (status != "Pending Refund")
throw "Status needs to be \"Pending Refund\" in order to create a Credit Memo and Customer Refund.";
var paymentMethod = returnAuth.getFieldValue("custbody_cc_payment_method");
var creditMemo = nlapiTransformRecord("returnauthorization", returnAuthId, "creditmemo");
var creditMemoId = nlapiSubmitRecord(creditMemo);
var creditMemo = nlapiLoadRecord("creditmemo", creditMemoId);
var creditMemoTransId = creditMemo.getFieldValue("tranid");
nlapiLogExecution("debug", "Credit Memo Id", creditMemoId);
// create the Customer Refund record
var customerRefund = nlapiCreateRecord("customerrefund", {
recordmode: "dynamic"
});
customerRefund.setFieldValue("customer", creditMemo.getFieldValue("entity"));
customerRefund.setFieldValue("paymentmethod", paymentMethod.id);
var account = ifxFindRecord.find("account", "number", "1099");
customerRefund.setFieldValue("account", account.id);
customerRefund.setFieldValue("trandate", nlapiDateToString(nlapiStringToDate(this.today())));
customerRefund.setFieldValue("total", creditMemo.getFieldValue("total"));
customerRefund.setFieldValue("memo", "Created from Credit Memo #" + creditMemoTransId);
customerRefund.setFieldValue("custbody_ifx_created_from", creditMemoId);
var credits = nlapiSearchRecord("creditmemo", null, new nlobjSearchFilter("createdfrom", null, "is", returnAuth.id), null);
nlapiLogExecution("debug", "line count", customerRefund.getLineItemCount("apply"));
for (var i = 1, len = customerRefund.getLineItemCount("apply"); i <= len; i++) {
nlapiLogExecution("debug", "line item ",
"id: " + customerRefund.getLineItemValue("apply", "doc", i) +
" apply: " + customerRefund.getLineItemValue("apply", "apply", i) +
" due: " + customerRefund.getLineItemValue("apply", "due", i) +
" amount: " + customerRefund.getLineItemValue("apply", "amount", i));
}
for (var iCredit = 0; iCredit < credits.length; iCredit++) {
var creditId = credits[iCredit].getId();
for (var i = 1, len = customerRefund.getLineItemCount("apply"); i <= len; i++) {
nlapiLogExecution("debug", "line item doc", customerRefund.getLineItemValue("apply", "doc", i));
if (customerRefund.getLineItemValue("apply", "doc", i) == creditId) {
customerRefund.setLineItemValue("apply", "apply", i, "T"); // mark apply as true
customerRefund.setLineItemValue("apply", "amount", i, customerRefund.getLineItemValue("apply", "due", i));
nlapiLogExecution("debug", "line apply");
break;
}
}
}
for (var i = 1, len = customerRefund.getLineItemCount("apply"); i <= len; i++) {
nlapiLogExecution("debug", "line item ",
"id: " + customerRefund.getLineItemValue("apply", "doc", i) +
" apply: " + customerRefund.getLineItemValue("apply", "apply", i) +
" due: " + customerRefund.getLineItemValue("apply", "due", i) +
" amount: " + customerRefund.getLineItemValue("apply", "amount", i));
}
nlapiSubmitRecord(customerRefund, true);
Но я получаю ошибку
USER_ERROR You must enter at least one line item for this transaction
Выходные данные отладки показывают, что есть 3 строки подсписка, 1 из которых была применена.
Этот код работал до того, как в этой учетной записи был обновлен последний выпуск 2016 R1.
Где я ошибся или что я могу попытаться обойти эту ошибку?