Netsuite SuiteScript 2.0:对发票应用部分客户付款时引发错误
在此方面的任何帮助都将不胜感激 我正在使用map/reduce脚本创建一个新的客户付款记录(来自发票记录),这是发票的部分付款。此操作需要在映射阶段进行 例:发票上的应付金额是(比如)26.66英镑,我想对此支付2.00英镑 应用发票全额付款时,以下代码段似乎有效:Netsuite SuiteScript 2.0:对发票应用部分客户付款时引发错误,netsuite,suitescript,suitescript2.0,Netsuite,Suitescript,Suitescript2.0,在此方面的任何帮助都将不胜感激 我正在使用map/reduce脚本创建一个新的客户付款记录(来自发票记录),这是发票的部分付款。此操作需要在映射阶段进行 例:发票上的应付金额是(比如)26.66英镑,我想对此支付2.00英镑 应用发票全额付款时,以下代码段似乎有效: var customerpayment = record.transform({ fromType : rectype, fromId: recid,
var customerpayment = record.transform({
fromType : rectype,
fromId: recid,
toType: 'customerpayment',
isDynamic: true
})
if (amount > 0){
var linecount = customerpayment.getLineCount({ sublistId: 'apply' });
for (var i = 1; i < linecount; i++) {
var refnum = customerpayment.getCurrentSublistValue({sublistId: 'apply', fieldId: 'refnum', line: i });
if (refnum == tranid) {
log.audit ('refnum == tranid. Line no: ' + i, refnum + ' | ' + tranid);
//isDynamic = TRUE
customerpayment.selectLine({sublistId: 'apply', line: i });
//Mark "apply' FALSE to clear the apply box (this would clear the "payment" header field as well)
customerpayment.setCurrentSublistValue({sublistId: 'apply', fieldId: 'apply', value: false });
//Now set the payment header field with the amount you want to apply
customerpayment.setValue({fieldId: 'payment', value: amount});
//Now select TRUE on apply. This (should) copy/paste the payment amount automatically as it does via the UI.
customerpayment.setCurrentSublistValue({sublistId: 'apply', fieldId: 'apply', value: true });
//For sanity sake, just populate the apply 'total' line with the same amount as payment field. In case it did not do it automatically.
customerpayment.setCurrentSublistValue({sublistId: 'apply', fieldId: 'total', value: amount });
var getTotal = customerpayment.getCurrentSublistValue({sublistId: 'apply', fieldId: 'total', line: i });
var getAllTotal = customerpayment.getValue({fieldId: 'payment'});
//Quick check that 'payment' header field and apply total field are the same
log.audit ('payment | payment line', getAllTotal + ' | ' + getTotal);
break;
}
}
//Now save record
var payment_id = customerpayment.save({
enableSourcing : true,
ignoreMandatoryFields: true
})
var customerpayment=record.transform({
fromType:rectype,
fromId:recid,
toType:“customerpayment”,
isDynamic:对
})
如果(金额>0){
var linecount=customerpayment.getLineCount({sublistId:'apply'});
对于(变量i=1;i
当调整小于发票上应付金额的金额时,上述相同代码会引发以下错误
我已经到达了霍尔特在这一点上,所以任何援助将不胜感激。
有趣的是,我已经成功地创建了一个用户事件脚本来实现这一点。
不确定是否是由于脚本类型可能阻止此操作?
提前感谢!当您创建付款记录时,您必须在正文级别设置付款金额。由于您处于动态模式,因此必须在开始应用之前设置付款金额
customerpayment.setValue({fieldId:'payment', value:amount});
customerpayment.setValue({fieldId:'autoapply', value:false}); //so only the invoice of interest will receive the payment
然后应用到你的线路上
if(refNum == tranid){
customerpayment.setCurrentSublistValue({sublistId: 'apply', fieldId: 'apply', value: true }); // IIRC this is all you need to do. I think in dynamic mode NS fills in the amount or the amount owing whichever is less. But if not proceed:
var canApply = Math.min(amount, customerpayment.getCurrentSublistValue({sublistid:'apply', fieldId:'amount'}));
customerpayment.setCurrentSublistValue({sublistId: 'apply', fieldId: 'amount', value: canApply});
break;
}
创建付款记录时,您必须在主体级别设置付款金额。由于您处于动态模式,您必须在开始申请之前设置付款金额
customerpayment.setValue({fieldId:'payment', value:amount});
customerpayment.setValue({fieldId:'autoapply', value:false}); //so only the invoice of interest will receive the payment
然后应用到你的线路上
if(refNum == tranid){
customerpayment.setCurrentSublistValue({sublistId: 'apply', fieldId: 'apply', value: true }); // IIRC this is all you need to do. I think in dynamic mode NS fills in the amount or the amount owing whichever is less. But if not proceed:
var canApply = Math.min(amount, customerpayment.getCurrentSublistValue({sublistid:'apply', fieldId:'amount'}));
customerpayment.setCurrentSublistValue({sublistId: 'apply', fieldId: 'amount', value: canApply});
break;
}
如果同一条记录被多次映射,您将耗尽资金。不要在映射阶段执行类似的操作。当然。但是在循环的两次迭代中,函数的第一个操作是应用部分付款,但这很遗憾会引发错误。如果失败,下一次迭代将应用剩余资金。在在他的情况下,这是发票的全部金额,它成功地与上面的代码一起工作。如果同一条记录被映射多次,您将耗尽可应用的资金。不要在映射阶段执行类似的操作。当然。但是在循环的两次迭代中,函数的第一个操作是应用部分付款,但这不幸地触发了e错误。如果失败,下一次迭代将应用剩余的资金。在这种情况下,它是成功使用上述代码的发票的全部金额。此行:customerpayment.setCurrentSublistValue({sublistId:'apply',fieldId:'amount',value:canApply});-是否应为“fieldId:“总计”?否。总计是应用于行交易的“应用”和“信用”子列表中的金额之和。例如,在UI中输入“金额”(在标记为“付款”的列中),并显示在“总计”(在原始金额下)。感谢您的帮助。是否有一种方法可以通过编程方式“清除”所有在“应用”上标记为TRUE的标志,而无需在每一行条目上运行循环(最多可以有10000行)?类似于付款记录上现有的“清除”按钮的方法会有所帮助。我之所以提出此问题,是因为出于某种原因,脚本(似乎)随机将付款应用于完全不同的发票(与最初转换的发票不同)。如果不使用动态模式,脚本将运行得更快。您还可以使用初始化参数查看是否可以使用auto apply False打开它此行:customerpayment.setCurrentSublistValue({sublistId:'apply',fieldId:'amount',value:canApply});-这不应该是“fieldId:'total'?否。总计是应用于行交易的“apply”和“credit”子列表上的金额之和。例如,在UI中输入“amount”(在t中)