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