I am working through a free freight script in our NetSuite environment. I have the code looking at the line item in which has a check box for "Exclude Free Freight" on each line - this is pulled from the item master. The problem is, I cannot seem to get the IF statement to run this through correctly. Ultimately, I am asking to sum up all the excluded items on the final variable. Here is my code.
try{
var totalQuantity = 0;
var flTotalItemAmount = 0;
var flAmount = 0;
var itemCount = newSOIDbfs.getLineCount('item');
log.debug("itemCount:", itemCount);
for (var i = 0; i < itemCount; i++) {
var stExcludeFromFreeFreight = newSOIDbfs.getSublistValue('item', 'custcol_exclude_from_free_freight', i);
if(stExcludeFromFreeFreight != 'F')
{
log.debug("Free 1:", stExcludeFromFreeFreight);
flAmount = newSOIDbfs.getSublistValue('item', 'amount', i);
log.debug("flAmount:", flAmount);
flTotalItemAmount = forceParseFloat(flTotalItemAmount) + forceParseFloat(flAmount);
log.debug("flTotalItemAmount:", flTotalItemAmount);
} // end if statement
} // end for loop
} // end try statement
catch(exception){
log.debug("GetInputDate Error Message:",exception);
}
The resulting Debug looks like this:
The end result is we have 3 lines on the sales order, 2 lines are free freight eligible and one line is free freight excluded. Final variable flTotalItemAmount should be $183.75.
Anybody see what I am missing and why the IF statement is taking lines 0 and 1 into account?
In SuiteScript 2.x
, checkbox values are booleans - true
if the checkbox is checked; false
if it is not checked. You can see evidence of this in your Free 1
log statements.
Your comparison condition can be reduced to if (stExcludeFromFreeFreight)
.