如何在不看到此错误的情况下创建客户退款“USER_ERROR您必须为此交易输入至少一个订单项”?

时间:2016-04-13 20:55:25

标签: netsuite suitescript

我正在尝试通过退货授权和贷记凭证创建客户退款。错误消息听起来像我没有任何订单项,即使至少有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个已应用。

One of the three sub list items was applied to the Customer Refund

此代码在最新的2016 R1版本在此帐户上更新之前正在运行。

我哪里出错或者我可以尝试通过此错误?

0 个答案:

没有答案