此类型脚本代码引发&Quot;RangeError:超过最大调用堆栈大小错误,但仅当存在多个项时 [英] This TypeScript code throws a "RangeError: Maximum call stack size exceeded" error, but only when there are multiple items
本文介绍了此类型脚本代码引发&Quot;RangeError:超过最大调用堆栈大小错误,但仅当存在多个项时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很好奇是否有人遇到过这个问题。我假设这可能是在子列表Changed()被解雇时发生的某种递归,但我想不出如何修复它。
export function sublistChanged (ctx: EntryPoints.Client.sublistChangedContext) {
const rec = X.getTx(ctx)
const total = _.sumBy(rec.item, (line: POItemSublist | TOItemSublist) => line.quantity * line.custcol_atlas_item_weight!)
rec.custbody_totalitemweightorder = total
}
推荐答案
看起来您正在使用带下划线的文字脚本和其他库。
国际海事组织为使NetSuite更像"传统"环境所做的努力相当艰难。
只需使用NetSuite更友好的迭代器,就可以非常容易地管理大多数列表理解。我将此作为一个代码片段:
function iter(rec:record.Record, listName, cb, doReverse? :boolean){
var i = 0;
var getV = function (fld){
return rec.getSublistValue({sublistId:listName, fieldId:fld, line:i});
};
if(doReverse){
i = rec.getLineCount({sublistId:listName}) - 1;
for(; i>= 0; i--){
cb(i, getV);
}
}else{
var lim = rec.getLineCount({sublistId:listName});
for(; i< lim; i++){
cb(i, getV);
}
}
}
因此您的代码可能如下所示:
export function sublistChanged (ctx: EntryPoints.Client.sublistChangedContext) {
const rec = ctx.currentRecord;
let total = 0;
iter(rec, 'item', (idx, getV)=>{
total += getV('quantity') * getV('custcol_atlas_item_weight')!;
});
rec.setValue({fieldId:'custbody_totalitemweightorder' ,value:total, ignoreFieldChange:true, forceSyncSourcing: true});
}
如果希望触发正常的下游事件处理,可以跳过 IgnreFieldChange,但在设置总权重字段时可能需要此选项,因此通常也会触发脚本。 forceSyncSourcing使setValue操作在下一个操作发生之前完全完成。 这篇关于此类型脚本代码引发&Quot;RangeError:超过最大调用堆栈大小错误,但仅当存在多个项时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文