【发布时间】:2020-08-03 17:01:16
【问题描述】:
我正在尝试在 NetSuite 中支付未结发票。我的目标是支付发票并返回“已全额支付”状态。
我可以使用下面的代码非常轻松地创建客户付款记录,但我似乎无法根据实际发票分配付款。当我执行人工付款(见图)时,会显示一个未结发票列表并且用户进行选择。
在 SuiteScript 中,我模仿了这一点,并为该客户创建了一个未结发票记录集。遍历记录集并检查匹配的发票 ID。如果找到匹配的发票 ID,我将更新这些字段,这两个字段都位于 apply sublist
record.setLineItemValue('apply', 'amount', r, '1.03');
record.setLineItemValue('apply', 'apply', r, 'T');
但是,这给了我以下错误:“您尝试了无效的子列表或订单项操作。您要么尝试访问不存在的行上的字段,要么尝试在静态子列表中添加或删除行”。
function postRESTlet(dataIn) {
var record = null;
var err = new Object();
var rectype = "customerpayment";
var id = 5915556;
try{
record = nlapiCreateRecord(rectype);
record.setFieldValue('currency', 1); // GBP
record.setFieldValue('customer', 40562);
record.setFieldValue('customform', 118);
record.setFieldValue('exchangerate', '1.00');
record.setFieldValue('payment', '1.03');
record.setFieldValue('paymentmethod', 8);
record.setFieldValue('account', 154);
var records = nlapiSearchRecord('invoice', null, [
new nlobjSearchFilter('status', null, 'is', 'CustInvc:A'), // Open Invoices
new nlobjSearchFilter('entity', null, 'is', 40562), // Entity
new nlobjSearchFilter('mainline', null, 'is', 'T') // Mainline True
], [
new nlobjSearchColumn('internalid').setSort(false)
]);
if (!records){
nlapiLogExecution('DEBUG', '0 Records Found');
return 'no records found';
};
// Loop all Open Invoices for this entity
for (var r=0; r<records.length; r++) {
// Check for match
if(id == records[r].getId()) {
// Update sublist
//record.setLineItemValue('apply', 'amount', r, '1.03');
//record.setLineItemValue('apply', 'apply', r, 'T');
}
}
var recordId = nlapiSubmitRecord(record,false,true);
var nlobj = nlapiLoadRecord(rectype,recordId);
return nlobj;
} catch(err){
var message = (!!err.message)?err.message:"An unexpected error ocurred";
message += (!!dataIn.id)?("Record ID is: " + dataIn.id):"No ID supplied" + err.message;
return message;
}
}
有谁知道我需要执行哪些步骤才能将付款分配给单个发票。
提前致谢:)
更新的 WORKING RESTLET(以防它帮助其他人):
function postRESTlet(dataIn) {
var id = dataIn[0]['sid'];
var entity = dataIn[0]['entity'];
var amount = dataIn[0]['amount'];
var paymethod = dataIn[0]['paymethod'];
var payaccount = dataIn[0]['payaccount'];
var record = null;
var err = new Object();
var rectype = "customerpayment";
var paymentapplied = 0;
try {
var records = nlapiSearchRecord('invoice', null, [
new nlobjSearchFilter('status', null, 'is', 'CustInvc:A'), // Open Invoices
new nlobjSearchFilter('entity', null, 'is', entity), // Entity
new nlobjSearchFilter('mainline', null, 'is', 'T') // Mainline True
], [
new nlobjSearchColumn('internalid').setSort(false)
]);
if (!records){
nlapiLogExecution('DEBUG', 'No Records Found');
return 'no records found';
};
// Loop all Open Invoices for this entity
for(var r=0; r<records.length; r++ ) {
if(records[r].getId() == id) { // The Invoice id matches
// Transform below does not appear documented; but works as expected
var deposit = nlapiTransformRecord('invoice', records[r].getId(), 'customerpayment');
deposit.setFieldValue('trandate', nlapiDateToString(new Date()));
deposit.setFieldValue('currency', 1); // GBP
deposit.setFieldValue('customer', entity);
deposit.setFieldValue('customform', 118);
deposit.setFieldValue('exchangerate', '1.00');
deposit.setFieldValue('payment', amount);
deposit.setFieldValue('paymentmethod', paymethod);
deposit.setFieldValue('account', payaccount);
// Walk the invoice list that we want to apply; find the invoice we are working on
var a = deposit.getLineItemCount('apply');
for(var i = 1; i <= a; i++) {
if(deposit.getLineItemValue('apply', 'internalid', i) == id ) {
nlapiLogExecution('DEBUG', 'working on invoice line:' + i, deposit.getLineItemValue('apply', 'refnum', i));
deposit.setLineItemValue('apply', 'amount', i, deposit.getLineItemValue('apply', 'total', i));
deposit.setLineItemValue('apply', 'apply', i, 'T');
};
};
paymentapplied = 1;
nlapiSubmitRecord(deposit);
return 'Payment Completed';
}
};
if(paymentapplied == 0)
return 'No Payment made. Is the Invoice already Paid?';
} catch(err){
var message = (!!err.message)?err.message:"An unexpected error ocurred";
return message;
}
}
【问题讨论】:
标签: netsuite suitescript invoice