使用RESTlet在NetSuite中支付发票(全额支付)
我正在尝试用NetSuite支付未结发票。我的目标是支付发票并使其返回“已全额支付”状态 我可以使用下面的代码很容易地创建客户付款记录,但我似乎无法根据实际发票分配付款。当我执行手动付款(见图)时,将显示未结发票的列表,用户将进行选择 在SuiteScript中,我模仿了这一点,并为该客户创建了未结发票记录集。遍历记录集并检查匹配的发票ID。如果找到匹配的发票ID,我将更新这些字段,这两个字段都在 但是,这会导致以下错误:“您尝试了无效的子列表或行项目操作。您正在尝试访问不存在的行上的字段,或者正在尝试从静态子列表中添加或删除行。”使用RESTlet在NetSuite中支付发票(全额支付),netsuite,suitescript,invoice,Netsuite,Suitescript,Invoice,我正在尝试用NetSuite支付未结发票。我的目标是支付发票并使其返回“已全额支付”状态 我可以使用下面的代码很容易地创建客户付款记录,但我似乎无法根据实际发票分配付款。当我执行手动付款(见图)时,将显示未结发票的列表,用户将进行选择 在SuiteScript中,我模仿了这一点,并为该客户创建了未结发票记录集。遍历记录集并检查匹配的发票ID。如果找到匹配的发票ID,我将更新这些字段,这两个字段都在 但是,这会导致以下错误:“您尝试了无效的子列表或行项目操作。您正在尝试访问不存在的行上的字段,或
函数postreslet(数据输入){
var记录=null;
var err=新对象();
var rectype=“customerpayment”;
var-id=5915556;
试一试{
记录=NLAPIREATERECORD(重新类型);
record.setFieldValue('currency',1);//英镑
记录.setFieldValue('customer',40562);
record.setFieldValue('customform',118);
record.setFieldValue('exchangerate','1.00');
记录.setFieldValue('payment','1.03');
record.setFieldValue('paymentmethod',8);
记录.setFieldValue('账户',154);
var记录=nlapiSearchRecord('发票'),空[
新的nlobjSearchFilter('status',null,'is','CustInvc:A'),//未结发票
新的nlobjSearchFilter('entity',null,'is',40562),//entity
新的nlobjSearchFilter('mainline',null,'is','T')//mainline True
], [
新的nlobjSearchColumn('internalid')。setSort(false)
]);
如果(!记录){
nlapiLogExecution('调试','找到0条记录');
返回“未找到记录”;
};
//循环此实体的所有未结发票
对于(var r=0;r使用记录转换而不是创建来将发票转换为客户付款。请参阅nlapiTransformRecord()
的帮助文档
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;
}
}
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;
}
}