title: email notification if cell is changed
body: <p>need help with google script. I have multiple row <a href="https://docs.google.com/spreadsheet/ccc?key=0AqmhWQ_A7q_adFU2cnRKRlZGSlFkWF9WeXhqblFFWmc&amp;usp=sharing">spreadsheet</a>. </p>
  
  <blockquote>
    <p><strong>Need a script that does the following:</strong></p>
    
    <p>If any cell in column G has been changed, then send email notification
    to custom address with information from this row: information from
    cell D and new value of cell G.</p>
  </blockquote>
  
  <p><strong>UPD</strong></p>
  
  <p>I found useful information:</p>
  
  <pre><code>function emailNotification() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getActiveSheet();
    var cell = ss.getActiveCell().getA1Notation();
    var cellvalue = ss.getActiveCell().getValue().toString();
    var recipient = "me@gmail.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);
  };
  </code></pre>
  
  <p>This script tracks the changes in the entire table. And I would like track changes only in column G, and get values ​​from column D.</p>
  
  <blockquote>
    <p><strong>Question:</strong> </p>
    
    <p>How to get the value of the cell in column D when the value has
    changed cell in column G</p>
  </blockquote>
  
  <p><strong>Finally script — answer to my question</strong></p>
  
  <p><a href="https://docs.google.com/spreadsheet/ccc?key=0AqmhWQ_A7q_adFU2cnRKRlZGSlFkWF9WeXhqblFFWmc&amp;usp=sharing">spreadsheet</a></p>
  
  <pre><code>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@gmail.com";
    var message = '';
    if(cell.indexOf('G')!=-1){ 
      message = sheet.getRange('D'+ sheet.getActiveCell().getRowIndex()).getValue()
    }
    var subject = 'Update to '+sheet.getName();
    var body = sheet.getName() + ' has been updated. Visit ' + ss.getUrl() + ' to view the changes on row: «' + row + '». New comment: «' + cellvalue + '». For message: «' + message + '»';
    MailApp.sendEmail(recipients, subject, body);
  };
  </code></pre>
  
  <p>Set trigger on onEdit and script will work fine</p>