This is a really strange issue, and I'm not sure how to fix it. I have a problem with my script where one of the conditions in my "if" statement doesn't evaluate correctly.
Here is my code:
function saveRecordItemFulfillment(type) { var error = ''; //LOAD CURRENT ID var curr_record_id = nlapiGetRecordId(); //LOAD CURRENT FULFILLMENT RECORD try { try { curr_order = nlapiLoadRecord('salesorder', nlapiGetFieldValue('createdfrom')); } catch(err) { curr_order = nlapiLoadRecord('transferorder', nlapiGetFieldValue('createdfrom')); } } catch(err2) { curr_order = nlapiLoadRecord('cashsale', nlapiGetFieldValue('createdfrom')); } var num_items = nlapiGetLineItemCount('item'); for(var x = 1; x <= num_items; x++) { var current_line_id = nlapiGetLineItemValue('item', 'itemkey', x); var current_line_name = nlapiGetLineItemValue('item', 'sitemname', x); var current_line_qty = nlapiGetLineItemValue('item', 'quantity', x); var current_line_onhand = nlapiGetLineItemValue('item', 'onhand', x); var current_line_desc = nlapiGetLineItemValue('item', 'itemdescription', x); if(current_line_desc != 'Shipping Charges' && current_line_desc != 'FREE FREIGHT' && current_line_qty > current_line_onhand) { if(error == '') { error = 'WARNING!nn'; } error = error + 'Insufficient stock available - ' + current_line_name + ' o/h: ' + current_line_onhand + ', req: ' + current_line_qty + 'n'; } } if(error != '') { error = error + 'nIf you wish to continue fulfilling this order, select Ok. To cancel, press Cancel.'; var doOverride = confirm(error); return doOverride; } return true; }Its purpose is to alert the person saving an item fulfillment if they are submitting a fulfillment that requests more items than are in the inventory.The problem I'm having is with this expression:if(current_line_desc != 'Shipping Charges' && current_line_desc != 'FREE FREIGHT' && current_line_qty > current_line_onhand)
More accurately, this particular part of it:current_line_qty > current_line_onhand
As you can see in the following screenshot, the issue is that the expression is resolving to true, when it should be resolving to false, but only the second and third times through the loop:Uploaded with ImageShack.usThe values of the current_line_qty and current_line_onhand are shown on the screenshot above labelled "req:" and "o/h" in the screenshot respectively. Clearly the correct data is being collected, it just isn't being evaluated properly each time through the loop.