Stop Script on Null Value in GSheets -


i trying send verification email on status change, can send based on column content, can't make stop once sees null value. puts in email confirmation tag regardless. need know how make stop on null if cell in column g blank. screenshot of sheet

var confirmation_sent = "confirmation_sent";  function sendconfirmation(e){  var sheet = spreadsheetapp.getactivesheet();   // fetch range of cells a1:range   var datarange = sheet.getdatarange ();   // fetch values each row in range.   var data = datarange.getvalues();   (var = 1; < data.length; ++i) {     var row = data[i];     var emailaddress = row[2];     var completemessage = "all set!  accoutn associate " + emailaddress + " has been deactivated"; // confrim account deactive     var cancelmessage = "per request, account associated " + emailaddress + " has not been deactivated."; // request cancelled     var invalidmessage = "the email address of " + emailaddress + " not accociated brightwheel account."; // invalid email     var confirmationsent = row[7];     var status = row[6];      var subject = "brightwheel deactivation request - " + emailaddress;     if (confirmationsent != confirmation_sent) {  // prevents sending duplicates       if (status != null) {return;}       else{       if (status = "complete - account deactivated") {mailapp.sendemail(emailaddress, subject, completemessage);}       if (status = "request canceled - account still active") {mailapp.sendemail(emailaddress, subject, cancelmessage);}       if (status = "not valid email - account not found") {mailapp.sendemail(emailaddress, subject, invalidmessage);}       }       sheet.getrange(i+1, 8).setvalue(confirmation_sent); //cell = index array + 1       // make sure cell updated right away in case script interrupted       spreadsheetapp.flush();     }   } } 

try replacing this:

if (status != null) {return;}       else{       if (status = "complete - account deactivated") {mailapp.sendemail(emailaddress, subject, completemessage);}       if (status = "request canceled - account still active") {mailapp.sendemail(emailaddress, subject, cancelmessage);}       if (status = "not valid email - account not found") {mailapp.sendemail(emailaddress, subject, invalidmessage);}       } 

with this:

 switch(data[i][6])   {     case 'complete - account deactivated':       mailapp.sendemail(emailaddress, subject, completemessage);       sheet.getrange(i+1, 8).setvalue(confirmation_sent);       break;     case 'request canceled - account still active':       mailapp.sendemail(emailaddress, subject, cancelmessage);       sheet.getrange(i+1, 8).setvalue(confirmation_sent);       break;     case 'not valid email - account not found':       mailapp.sendemail(emailaddress, subject, invalidmessage);       sheet.getrange(i+1, 8).setvalue(confirmation_sent);       break;     default:       break;//we don't want return here want break can continue on remain lines.   } 

i looking @ code , noticed should have included setting column prevents duplicate emails.

this works:

i tested it.

function sendconfirmation() {   var ss=spreadsheetapp.getactive();   var sh=ss.getactivesheet();   var rg=sh.getdatarange ();   var data=rg.getvalues();   var s=''   (var i=1;i<data.length;i++)    {     var completemessage = "all set!  accoutn associate " + data[i][2] + " has been deactivated";     var cancelmessage = "per request, account associated " + data[i][2] + " has not been deactivated.";     var invalidmessage = "the email address of " + data[i][2] + " not accociated brightwheel account.";     var subject = "brightwheel deactivation request - " + data[i][2];     if (!data[i][7])      {        switch(data[i][6])       {         case 'status1':           mailapp.sendemail(data[i][2], subject, completemessage);           //s+=utilities.formatstring('<br />i: %s email: %s subject: %s message: %s',i,data[i][2], subject, completemessage);           sh.getrange(i+1, 8).setvalue('confirmation_sent');           break;         case 'status2':           mailapp.sendemail(data[i][2], subject, cancelmessage);           //s+=utilities.formatstring('<br />i: %s email: %s subject: %s message: %s',i,data[i][2], subject, cancelmessage);           sh.getrange(i+1, 8).setvalue('confirmation_sent');           break;         case 'status3':           mailapp.sendemail(data[i][2], subject, invalidmessage);           //s+=utilities.formatstring('<br />i %s email: %s subject: %s message: %s',i,data[i][2], subject, invalidmessage);           sh.getrange(i+1, 8).setvalue('confirmation_sent');           break;         default:           break;//dont return break , go on next line.       }     }   }   //var ui=htmlservice.createhtmloutput(s);   //spreadsheetapp.getui().showmodelessdialog(ui, 'emails sent'); } 

the big problem return. stopped script in it's tracks. break in there go on next line. left debug stuff in there , simplified of status statements convenience during debugging.

this spreadsheet looks like:

enter image description here

this debug screen:

enter image description here


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -