1

I am looking to set up something where notifications are only sent out if a specific single cell is changed. I have little coding experience and have a general idea of what needs to be in place. From what I have gathered I have created a script but it has notifications for all cell changes. Any suggestions on changing to only notify on single cell would be appreciated.

function emailNotification() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getActiveSheet();
    var cell = ss.getActiveCell().getA1Notation();
    var cellvalue = ss.getActiveCell().getValue().toString();
    var recipient = "mail@mail.com";
    var subject = 'Update to '+sheet.getName();
    var body = sheet.getName() + ' has been updated. Visit ' + ss.getUrl() + ' to view the changes on cell: «' + cell + '» New cell value: «' + cellvalue + '»';
    MailApp.sendEmail(recipient, subject, body);
};
Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121

3 Answers3

0

Try changing

var cell = ss.getActiveCell().getA1Notation();
var cellvalue = ss.getActiveCell().getValue().toString();
to
var cell = ss.getRange(row, column); //Put in the row and column of your cell
var cellvalue = cell.getValue().toString();
Kelvin Chong
  • 222
  • 1
  • 3
  • 17
0

assuming that with 'changes' you mean manual edits, in order to 'limit' the script to a certain sheet and/or a certain cell you will have to check what the currently edited cell is. For example: if you only want the script to fire off when cell A1 of Sheet1 is edited, try something like:

function emailNotification(e) {
var sheet = e.source.getActiveSheet();
if (sheet.getName() !== 'Sheet1' || e.range.getA1Notation() !== 'A1') return;
var recipient = "mail@gmail.com";
var subject = 'Update to ' + sheet.getName();
var body = sheet.getName() + ' has been updated.\nVisit ' + e.source.getUrl() + ' to view the changes on cell A1.\nNew cell value: «' + e.value + '»';
MailApp.sendEmail(recipient, subject, body);
};

Change the sheet name and cell to suit and see if this works ?

JPV
  • 26,499
  • 4
  • 33
  • 48
-1
var cell = ss.getRange("F2:F50"); //Put in the row and column of your cell

I'm working with this as well. The script is still sending notification if any cell is edited, not just column F

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
Tony D
  • 3
  • 2
  • JPV you are a hero! Thank you. It is now narrowed down to a single cell. To complete the project, I must send notification if ANY cell in ROW F edited. 'if (sheet.getName() !== 'Sheet1' || e.range.getA1Notation() !== 'A1') return;' I edited 'A1' to read 'F:F'. That didn't work. I also tried 'F2,F3,F4' ..etc. That didn't work either – Tony D Dec 04 '15 at 16:54