I am using google sheets to record our printer cartridge inventory, and using script editor to check the cells C2:C50, and send out an alert email if one cell falls below 1 after editing. I finally have it set up where it will work if C2 falls to 0, but that is it. If C3:C50 go to 0 while C2 is >=1, nothing goes out. If C3:C50 go to 0 while C2 is 0, an email will be sent out for C2 only. I'm trying to figure out how to get the function to look at C3:C50. And its not giving out any errors when running. Just not working as expected.
This is what I got so far...
function CheckInventory()
{
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("CartInv");
var range = sheet.getRange('C2:C50'); \\**I think the problem is here somewhere!**
var ui = SpreadsheetApp.getUi();
if (range.getColumn() <= 3 &&
range.getLastColumn() >= 3)
{
var row = range.getRow();
var values = SpreadsheetApp.getActiveSheet().getRange(row,3).getValues();
if(values<1)
{
var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("CartInv").getRange("K2");
var emailAddress = emailRange.getValues();
var cartridge = SpreadsheetApp.getActiveSheet().getRange(row,1).getValue();
var message = "ATTENTION! "+cartridge+" is out. Order more.";
var subject = 'Test Awareness Mail';
MailApp.sendEmail(emailAddress, subject, message);
}
}
}
The main problem I'm running into is that if(values<1) reads only C2. I'm trying to get it to send an email for every cell in the range C2:C50