Google Apps Script: How to pull values from column A based on values in column E and send all values in one email? -


i'm trying create script student attendance spreadsheet in column e string "x". each instance of "x", string column (the student name) added body of email. i'm pretty new javascript, although have been studying basics. i've done lot of research , found scripts able modify send individual email each instance of x in e. however, have not been able figure out how combine information single email.

here's have far:

function email_reminderns() {    var sheet = spreadsheetapp.getactivespreadsheet().getsheetbyname("july_august"),       email_sent = "email_sent",       statusarray = sheet.getdatarange().getvalues();   var class = statusarray[0][8],        status = "x",       email   = "xxxx"    (i=7;i < statusarray.length;i++){     var emailsent = statusarray[i][84];     if (status == statusarray[i][4] & emailsent != email_sent) {        var student = statusarray[i][0];       var body    = "this no-show report " +student+ " " + class;       var subject = "no-show report " + student+ " " + class;       mailapp.sendemail(email,subject,body,{noreply : true});       sheet.getrange(i+1, 85).setvalue(email_sent);       spreadsheetapp.flush();     }   } } 

i realize i'll need move sendemail function outside if statement. tried create array names , join string , add body of email, i've had no luck. ended sending last name instead of of them.

if has suggestions me grateful.

first set variables keep track of student did not show up:

var students = []; var student_rows = []; 

then, add student these arrays when x found:

if (status == statusarray[i][4] & emailsent != email_sent) {   var student = statusarray[i][0];   students.push(student);   student_rows.push(i+1); } 

then send email student names combined (outside of loop said)

var body    = "this no-show report " + students.join(', ') + " " + class; var subject = "no-show report " + students.join(', ') + " " + class; mailapp.sendemail(email,subject,body,{noreply : true}); 

finally update spreadsheet indicating names in email:

for (var i=0; i<student_rows.length; i++) {   sheet.getrange(student_rows[i], 85).setvalue(email_sent);   spreadsheetapp.flush(); } 

here's complete script:

function email_reminderns() {    var sheet = spreadsheetapp.getactivespreadsheet().getsheetbyname("july_august"),       email_sent = "email_sent",       statusarray = sheet.getdatarange().getvalues();   var class = statusarray[0][8],        status = "x",       email   = "francis@bposolutions.com";    var students = [];   var student_rows = [];    (i=7;i < statusarray.length;i++){     var emailsent = statusarray[i][84];      if (status == statusarray[i][4] & emailsent != email_sent) {       var student = statusarray[i][0];       students.push(student);       student_rows.push(i+1);     }   }    var body    = "this no-show report " + students.join(', ') + " " + class;   var subject = "no-show report " + students.join(', ') + " " + class;   mailapp.sendemail(email,subject,body,{noreply : true});    (var i=0; i<student_rows.length; i++) {     sheet.getrange(student_rows[i], 85).setvalue(email_sent);     spreadsheetapp.flush();   } } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -