【问题标题】:Creating a Customer Refund record for a Customer Deposit associated with a Sales Order为与销售订单关联的客户存款创建客户退款记录
【发布时间】:2016-02-03 09:11:49
【问题描述】:

我快到了。我正在挂断将客户存款添加到客户退款中。这是我用来创建客户退款的代码。

var ifxCreateCustomerRefund = {
    fromSalesOrder: function () {
        var salesOrder = nlapiGetNewRecord();
        var customerRefund = nlapiCreateRecord('customerrefund');           

        customerRefund.setFieldValue("customer", salesOrder.getFieldValue("entity"));
        customerRefund.setFieldValue("paymentmethod", salesOrder.getFieldValue("custbody_ifx_cc_payment_method"));
        var account = ifxFindRecord.find("account", "number", "1099");
        customerRefund.setFieldValue("account", account.id);
        nlapiLogExecution("debug", "today", nlapiDateToString(nlapiStringToDate(this.today())));
        customerRefund.setFieldValue("trandate", nlapiDateToString(nlapiStringToDate(this.today())));

        nlapiLogExecution("debug", "order #", salesOrder.getFieldValue("tranid"));
        nlapiLogExecution("debug", "deposittransaction", JSON.stringify(salesOrder.getFieldValue("deposittransaction")));

        var deposits = nlapiSearchRecord("customerdeposit", null, new nlobjSearchFilter("createdfrom", null, "is", salesOrder.id), null);
        nlapiLogExecution("debug", "customer deposits", JSON.stringify(deposits));

        customerRefund.insertLineItem("deposit", 1);
        customerRefund.setLineItemValue("deposit", "doc", 1, deposits[0].id);
        customerRefund.setLineItemValue("deposit", "apply", 1, true);

        nlapiSubmitRecord(customerRefund);
    },
    today: function () {
        var dt = new Date();
        var str = (dt.getMonth() + 1) + "/" + dt.getDay() + "/" + dt.getFullYear();
        return nlapiDateToString(nlapiStringToDate(str));
    }
};

它给了我这个错误:

您尝试了无效的子列表或订单项操作。你是 要么尝试访问不存在的行上的字段,要么您正在 尝试在静态子列表中添加或删除行。

您能帮我将与销售订单相关的客户押金用于客户退款吗?

【问题讨论】:

    标签: netsuite


    【解决方案1】:

    客户退款需要使用客户 ID 进行初始化,然后可用的存款已经存在。改编自我之前的回答:

    var cr = nlapiCreateRecord('customerrefund',{entity:salesOrder.getFieldValue("entity")}); // id of customer
    cr.setFieldValue('paymentmethod', salesOrder.getFieldValue("custbody_ifx_cc_payment_method"));
    ... // do your account assignment etc.
    
    var deposits = nlapiSearchRecord("customerdeposit", null, new nlobjSearchFilter("createdfrom", null, "is", salesOrder.getId()), null);
     var depositId = deposits[0].getId();
     for(var i = cr.getLineItemCount('deposit'); i>0; i--){
        if(depositId == cr.getLineItemValue('deposit', 'doc', i)){
        cr.setLineItemValue('deposit', 'apply', i, 'T');  // need this for at least one line.
        break;
     }
    nlapiSubmitRecord(cr);
    

    【讨论】:

    • 谢谢@bknights,这正是我想要的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-11
    • 1970-01-01
    • 2016-05-06
    • 2023-04-06
    • 1970-01-01
    相关资源
    最近更新 更多