为与销售订单关联的客户存款创建客户退款记录
Creating a Customer Refund record for a Customer Deposit associated with a Sales Order
我快到了。我对将客户押金添加到客户退款中感到困惑。这是我用来创建客户退款的代码。
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));
}
};
给我这个错误:
You have attempted an invalid sublist or line item operation. You are
either trying to access a field on a non-existent line or you are
trying to add or remove lines from a static sublist.
你能帮我把与销售订单相关的客户定金用于客户退款吗?
客户退款需要使用客户 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);
我快到了。我对将客户押金添加到客户退款中感到困惑。这是我用来创建客户退款的代码。
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));
}
};
给我这个错误:
You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist.
你能帮我把与销售订单相关的客户定金用于客户退款吗?
客户退款需要使用客户 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);