Google Spreadsheets: email notifications for single cell

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);
};

Answers


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();

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 ?


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


Need Your Help

Ubuntu: Open Netbeans in specific workspace (using window matching)

ubuntu netbeans ubuntu-13.10 compiz

Using the CompizConfig Settings Manager on Ubuntu 13.10 I would like to assign Netbeans 7.4 to workspace 4 (viewport X=2, Y=2) and have it maximized. This approach works just fine for Chromium and

Android Text to Speech is broken while phone ringing

android text-to-speech

In my android application I am using the Text to Speech engine to have a piece of Text spoken. The speech code runs when phone is ringing. The speech is broken and I see following Warnings in the l...