google apps script - Restrict notifications sent for changes referenced in columns -
i referenced this post make launch calendar dates , names:
the 2 columns have 1 date (a) , other launch name/description (b). in ideal state, wanted send notifications when:
- there new launch entry name (b); not date entered yet (a)
- separately, sending update date changes (a) , referencing launch name (b); there won't case have date no launch name (unless i'm in process of entering 1 after other), there should not notifications sent if there's date entered , no corresponding b cell yet.
i'm seeing false positives code in following ways:
1.) if don't enter date (a) put text in column (b), i'm getting date email empty referencing (b); i'd restrict not send notification if corresponding cell in column empty
2.) i'm getting duplicate date (a) emails; has adding date when second 'if' condition present check column b (launch name); it's when add new date, receive 2 emails adding date.
3.) if enter launch name (b) no date (a), i'm getting both emails; happening when second if condition present. preference not receive date email if date cell (a) empty.
i noticed deletion , empty cells seems send notification emails.
function sendnotification() { var ss = spreadsheetapp.getactivespreadsheet(); var sheet = ss.getactivesheet(); var cell = ss.getactivecell().geta1notation(); var row = sheet.getactiverange().getrow(); var cellvalue = ss.getactivecell().getvalue().tostring(); var mycell = ss.getactiveselection(); var cellcol = mycell.getcolumn(); var recipients = "me@me.com"; var message = ''; if(cell.indexof('a')!=-1){ message = sheet.getrange('b'+ sheet.getactivecell().getrowindex()).getvalue() } var subject = ':date modification «' + message + '»'; var body = 'the launch tracker has been updated. \n\n\na date modification of: «' + cellvalue + '» has occured following user-facing change: «' + message + '» \n\n\nthis modification should reflected on launch calendar. \n\n\nvisit: ' + ss.geturl() + ' view modification, found in row: «' + row + '»'; mailapp.sendemail(recipients, subject, body); if (cellcol == 2) var subject = 'new addition of «' + cellvalue + '»'; var body = 'the waypoint tracker has been updated. \n\n\na new user-facing change of: «' + cellvalue + '» has been added. \n\n\nthis modification should reflected on launch calendar when date information added. \n\n\nvisit: ' + ss.geturl() + ' view modification, found in cell: «' + cell + '»'; mailapp.sendemail(recipients, subject, body); }
Comments
Post a Comment