I am trying to send emails automatically for each employee on the Quota Capacity Recommendation form if Difference in Demand & Production is above 10 or below -10.
When I run the script the emails get sent even if the value is within the acceptable range (-9 to 9).
function checkValue() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Quota Capacity Recommendation");
var num = sheet.getRange(2, 11).getValue(); //number of employees
for (var i = 2; i < num; i++) { //loop to get each employee
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Quota Capacity Recommendation");
var dif = sheet.getRange(i, 10).getValue(); //value to check
var rc = sheet.getRange(i, 9).getValue();
var name = sheet.getRange(i, 1).getValue();
if (dif > 10 || dif < -10) //condition
{
//GmailApp.sendEmail("user@domain.com",name+ " Quota Recommendation", name+ " has recommended quota change of " +rc);
GmailApp.sendEmail("otheruser@domain.com", name + " Quota Recommendation", name + " has recommended quota change of " + rc);
//MailApp.sendEmail("differentuser@domain.com",name+ " Quota Recommendation", name+ " has recommended quota change of " +rc);
}
}
}
if bigger than 10 or less than 10. So that is !=10.
It looks that the problem is that the values of column 10 (J) are percentages (the sample value es 20%) instead of integers 20.
You should have to change the value entered to be integers or the script tu use .1 instead or 10.