0
我有一个子列表的记录,并且该子列表的每个项目都是具有另一个子列表的记录。我想要的是,每个itemA获得每个itemA子列表的所有子列表。像这样优化netsuite脚本
Bill of lading1
->FulfillmentA
->Item123
->Item124
->Item125
->FulfillmentB
->Item224
->Item226
->Item227
我希望能够创造这样的表为具有2个应验提单1提单
Fulfillment | Item | Description | Qty
例如每比尔而且每个应验的有3个项目
BILL OF LADING #4
Fulfillment | Item | Description | Qty
-------------------------------------------
A | 123 | xxxx | 2
| 124 | xxxx | 1
| 125 | xxxx | 7
--------------------------------------------
B | 224 | xxxx | 1
| 226 | xxxx | 1
| 227 | xxxx | 1
我能做到这一点,问题是当一些fullfilment有一个像60-70应验,然后我得到一个脚本执行使用限制超出错误。
我的代码的基本想法是创建这样一个对象:
* {
* 70: {
* itemNumber : {
* description: xxxx,
* quantity: XX
* },
* itemNumber2 : {
* description: xxxx,
* quantity: XX
* },
* 71: { ...},
* ....
* }
然后用循环创建表。
我认为这个问题是这一行:
fulfillmentArray.push(nlapiLoadRecord('itemFulfillment', fullfillmentInternalIDArray[z]));
因为当我删除它在具有100个fullfilments它的工作原理
这里,BOL是我的代码:
var lines = record.getLineItemCount('recmachcustrecord_id_billoflading');
//Grab the fulfillment internal id
for(var i = 1; i <= lines; i++){
fullfillmentInternalIDArray.push(record.getLineItemValue('recmachcustrecord_id_billoflading', 'custrecord_fulfillment', i));
}
//Get the fulfillment number
for(var x = 1; x <= lines; x++){
fulfillmentNumberArray.push(record.getLineItemText('recmachcustrecord_id_billoflading', 'custrecord_fulfillment', x).replace(/Fulfillment|#|Item/g,""));
}
//Get the fulfillments and push them into an array
//And create an empty object with the fulfillment number
for(var z = 0; z < fullfillmentInternalIDArray.length; z++){
fulfillmentArray.push(nlapiLoadRecord('itemFulfillment', fullfillmentInternalIDArray[z]));
billOfLadingFulfillmentsObject[ fulfillmentNumberArray[z] ] = {};
}
然后创建对象的其余部分:
for(var j = 0; j < fulfillmentArray.length; j++){
itemCount = fulfillmentArray[j].getLineItemCount('item');
for(var y = 1; y <= itemCount; y++){
billOfLadingFulfillmentsObject[ fulfillmentNumberArray[j] ][ fulfillmentArray[j].getLineItemValue('item', 'itemname', y) ] = {};
}
for(var item in billOfLadingFulfillmentsObject){
for(var item2 in billOfLadingFulfillmentsObject[item]){
for(var y = 1; y <= itemCount; y++){
if(item2 === fulfillmentArray[j].getLineItemValue('item', 'itemname', y)){
billOfLadingFulfillmentsObject[ fulfillmentNumberArray[j] ][item2]['description'] = fulfillmentArray[j].getLineItemValue('item', 'itemdescription', y);
billOfLadingFulfillmentsObject[ fulfillmentNumberArray[j] ][item2]['quantity'] = fulfillmentArray[j].getLineItemValue('item', 'quantity', y);
}
}
}
}
}
我不知道如何进行优化,因此当有很多实现时,它不会引发脚本执行使用限制超出错误。