I am working on a function that will construct a bar code from a few data points within my spreadsheet for items in an inventory.
My issue/question is two fold:
When running through the
for loop
, I am getting this error message"TypeError: Cannot read property "length" from null."
While it looks like I have successfully loaded the ranges I want into veritable, I am not entirely sure as to how to call them, could you please tell me if I am calling them correctly within the
if
statement?
function barCodeBuilder(stockName) {
// Setting Ranges from prices table
var sheet = SpreadsheetApp.getActive();
var listNameRange = sheet.getRangeByName('MeterailsPricing!ITEM NAME');
var listSkuRange = sheet.getRangeByName('MeterailsPricing!INVENTORY SKU');
var listPriceRange = sheet.getRangeByName('MeterailsPricing!PRICE');
var listSupRange = sheet.getRangeByName('MeterailsPricing!SUPPLIER CODE');
//Errors begin here = TypeError: Cannot read property "length" from null
for(listCounter = 0; listCounter < listNameRange.length; listCounter++){
if(stockName == listNameRange[listCounter][0]){
var barCode = {
sku:listSkuRange[listCounter][0],
supCode:listSupRange[listCounter][0],
price:listPriceRange[listCounter][0]};
}
}
//final bar code assembly
var finalBarCode = barCode.sku + "-" + barCode.supCode + "-" + barCode.price;
return finalBarCode;
}
And as always, thank you all for taking the time to help me out.
Talk to you soon. Greg R.