google apps script - Update Date or Send Email when a Specific Range is Edited -
how tell cell c2 set date when cells a2 or b2 have been updated? further, how trigger sending of email function when a2 or b2 have been updated?
my issue onedit fires anytime document edited @ all, want action if specific range edited.
for sending of emails, i've found , edited script works, sends me email notifications whenever cell in document changed rather when column g changed. suggestions?
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 recipients = "me@email.com"; var message = 'cell value has been changed'; if(cell.indexof('g')!=-1){ message = sheet.getrange('d'+ sheet.getactivecell().getrowindex()).getvalue() } var subject = 'update '+sheet.getname(); var body = sheet.getname() + ' has been updated. visit ' + ss.geturl() + ' view changes on row: «' + row + '». new comment: «' + cellvalue + '». message: «' + message + '»'; mailapp.sendemail(recipients, subject, body); };
does have onedit() function being off?
for needs final scripts
i ended splitting in 2 separate functions. here finished scripts.
the first 1 email notifications
/* function send email when specified range edited * spreadsheets triggers must set onedit function */ function sendnotification() { var ss = spreadsheetapp.getactivespreadsheet(); var sheet = ss.getactivesheet(); //get active cell var mycell = ss.getactiveselection(); var cellcol = mycell.getcolumn(); var cellrow = mycell.getrow(); //define notification details var recipients = enteremailhere; var subject = "update "+ss.getname(); var body = ss.getname() + "has been updated. visit " + ss.geturl() + " view changes."; //check see if column or b trigger if (cellcol == editmecolumn) { //check row trigger if (cellrow == editmerow) { //send email mailapp.sendemail(recipients, subject, body); } //end sendnotification } }
and here 1 time stamps
/* function saves date in cell * every time specific row or column edited * spreadsheets triggers must set onedit function */ function setdate() { var ss = spreadsheetapp.getactivespreadsheet(); var sheet = ss.getactivesheet(); //get active cell var mycell = ss.getactiveselection(); var cellcol = mycell.getcolumn(); var cellrow = mycell.getrow(); //check see if column or b trigger if (cellcol == editmecolumn) { //check row trigger if (cellrow == editmerow) { //find cell , set date in defined cell var celldate = sheet.getrange(editmerow, editmecolumn); celldate.setvalue(new date()); //end set date } } }
this should work or @ least give idea similar. set trigger onedit()
function sendnotification() { var ss = spreadsheetapp.getactivespreadsheet(); var sheet = ss.getactivesheet(); //get active cell var mycell = ss.getactiveselection(); var cellcol = mycell.getcolumn(); var cellrow = mycell.getrow(); //check see if column or b trigger email if (cellcol == 1 || cellcol ==2) { //check row trigger email if (cellrow ==2) { //find cell , set date var celldate = sheet.getrange(2, 3); celldate.setvalue(new date()); //end set date var cellvalue = mycell.getvalue().tostring(); var recipients = "me@email.com"; var message = 'cell value has been changed'; if(cell.indexof('g')!=-1){ message = sheet.getrange('d'+ sheet.getactivecell().getrowindex()).getvalue() } var subject = 'update '+sheet.getname(); var body = sheet.getname() + ' has been updated. visit ' + ss.geturl() + ' view changes on row: «' + row + '». new comment: «' + cellvalue + '». message: «' + message + '»'; mailapp.sendemail(recipients, subject, body); } } }
Comments
Post a Comment