I have a function set up to look at a tab within a sheet, check for certain conditions and then send an email if those conditions are met. The body of the email is set up with certain variables that are comprised of columns from the sheet. The function seems to be working fine, but I'm receiving a warning from Apps Script about using "getValues()" instead of "getValue()" and minimizing calls to servers.
I've tried to grab the range of the spreadsheet into an array, but then I'm not sure how I can go ahead and define variables based off of individual columns within that array.
This is the code that I currently have. If it matters, I also have a separate function setup with this spreadsheet to move rows from one tab to another.
function emailNotification(){
var nowH=new Date().getHours();
var nowD=new Date().getDay();
if((nowD > 0 && nowD <6) && (nowH > 9.5 && nowH < 5.5)) {
var ss = SpreadsheetApp.openByUrl('spreadsheet url');
var dataSheet = ss.getSheetByName("tab name");
for (var i = 2; i <= dataSheet.getLastRow(); i++) {
var firstName = dataSheet.getRange(i, 5).getValue();
var lastName = dataSheet.getRange(i, 6).getValue();
var recipient = dataSheet.getRange(i, 3).getValue();
var isHired = dataSheet.getRange(i, 1).getValue();
var orgName = dataSheet.getRange(i, 11).getValue();
var emailSent = dataSheet.getRange(i, 18).getValue();
var body = "Hello" + "," + "\n" + "\n" + firstName + "
"+lastName + " " + "has been added to the"+ " " + orgName
+ "." + "\n" + "\n" + "Best," + "\n" + "Me";
var htmlText = body.replace(/\n/g,'<br\>');
var subject = "New Hire";
if (isHired == "Yes" && emailSent != "Email Notification
Sent" ) {
MailApp.sendEmail(recipient, "email", subject, body)
MailApp.sendEmail(recipient, subject, body,{
htmlBody : htmlText})
// MARK THE ROW AS COMPLETED
dataSheet.getRange(i, 18).setValue("Email Notification
Sent");
}
}
}
This is the message I receive:
Method Range.getValue is heavily used by the script File: Code Line: 57
Any assistant would be kindly appreciated.