I am trying to write a script to adjust quantity of a set of items based on the quantity chosen of a parent item. I am doing this in the recalc event. The code I have works but it literally takes 3 minutes or so on an estimate with 40 lines. Has anyone done anything like this and can tell me how to do it faster?
// Will take the quantity of a parent item selected and update all items in same product family function lineRecalc(type){ //Check to see if the type passed to the function is an item if (type == 'item') { var item = nlapiGetCurrentLineItemValue('item', 'item'); var isParent = nlapiGetCurrentLineItemValue('item', 'custcol_vcs_item_qty_updt'); if (isParent == 'T'){ var productFamily = nlapiGetCurrentLineItemValue('item', 'custcol_product_line'); var quantity = nlapiGetCurrentLineItemValue('item', 'quantity'); //Get the number of lines in the item object var count = nlapiGetLineItemCount('item'); var line = parseFloat(nlapiGetCurrentLineItemIndex('item')); setTimeout(function() { // Loop through all of the lines for (var i = line + 1; i <= count; i++) { // is this a parent item var family = nlapiGetLineItemValue('item', 'custcol_product_line', i); if (family == productFamily){ var item = nlapiGetLineItemValue('item', 'item', i); nlapiSelectLineItem('item', i); nlapiSetCurrentLineItemValue('item', 'item', item, true, true); nlapiSetCurrentLineItemValue('item', 'quantity', quantity, true, true); nlapiCommitLineItem('item'); // nlapiSetLineItemValue('item', 'quantity', i, quantity); } } }, 500); } } }