1
我很努力想知道为什么此循环无法正常工作。它似乎只是第一次迭代。由于有4个订单项,因此行项目计数记录4应循环4次。需要能够更新来自外部系统的订单项,以便我有一个外部ID,可以与现有的外部ID匹配。NetSuite - 订单项循环问题
var itemcount = update_record.getLineItemCount('item');
for (var i = 1; i <= itemcount; i++)
{
\t var a_id = update_record.getLineItemValue('item', 'custcol_ex_line_id', i);
\t var json_itemcount = jsonObject.item.length
\t for (var x = 0; json_itemcount != null && x < json_itemcount; x++)
\t {
\t \t var json_id = jsonObject.item[x].ex_line_id
\t \t if(json_id == a_id)
\t \t {
\t \t \t nlapiLogExecution('DEBUG', 'Match Found');
\t \t \t update_record.setLineItemValue('item', 'amount', i, jsonObject.item[x].amount)
\t \t \t var id = nlapiSubmitRecord(update_record, true);
\t \t \t return id;
\t \t }
\t \t else
\t \t {
\t \t \t nlapiLogExecution('DEBUG', 'no match found - no updates required');
\t \t }
\t }
}
"item": [{"item" : 38, "amount": 1786, "ex_line_id" : 111},
{"item" : 38, "amount": 1786, "ex_line_id" : 113},
]
}
谢谢,这似乎已经解决了这个问题! – MG2016
Grrr,抱歉,但发现一个问题。我还有其他地方 - 如果json_id与a_id不匹配,我将创建新的订单项。但是,如果毕竟比较完成并且没有匹配的话,我只希望它能够打到别的地方。现在,只要第一次比较完成,并且没有找到匹配,就会触发其他...但是,json_id可能会在几行之后存在 – MG2016