- This code is sending multiple emails with repetition because of for loop, i wanted it to send single email
function Buy() {
var ss=SpreadsheetApp.getActive();
var sheet=ss.getSheetByName("Buy");
var Cvalues=sheet.getRange(2,3,sheet.getLastRow()-1,1).getValues();
var Avalues=sheet.getRange(2,1,sheet.getLastRow()-1,1).getValues();
var results=[];
for(var i=0;i<Cvalues.length;i++){
if(Cvalues[i][0]<=-3){
results.push(" "+ Avalues[i]);
results.push("Price "+ Cvalues[i]);
MailApp.sendEmail('[email protected]', 'Buy Alert',results.join("n"));
}
}
}
- This code is sending email when if condition is met or not met (blank alert)
function Buy() {
var ss=SpreadsheetApp.getActive();
var sheet=ss.getSheetByName("Buy");
var Cvalues=sheet.getRange(2,3,sheet.getLastRow()-1,1).getValues();
var Avalues=sheet.getRange(2,1,sheet.getLastRow()-1,1).getValues();
var results=[];
for(var i=0;i<Cvalues.length;i++){
if(Cvalues[i][0]<=-3){
results.push(" "+ Avalues[i]);
results.push("Price "+ Cvalues[i]);
}
}
MailApp.sendEmail('[email protected]', 'Buy Alert',results.join("n"));
}
Send Single Email for FOR loop instead of multiple repetitive Emails, what other alternatives to achieve this efficiently without receiving multiple repetitive emails and blank email alerts