为与销售订单关联的客户存款创建客户退款记录

时间:2016-02-03 09:11:50

标签: netsuite

我越来越近了。我已经挂断了将客户存款添加到客户退款中。以下是我用来创建客户退款的代码。

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));
    }
};

它给了我这个错误:

  

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

您能否帮助我将与销售订单相关的客户存款应用于客户退款?

1 个答案:

答案 0 :(得分:3)

客户退款需要使用客户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);