Notify via email when a cell is updated in google spreadsheet

旧街凉风 提交于 2020-08-20 11:41:33

问题


I am new to script and added this script which worked:

function sendEmailAlert() {

    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var cellValue = ss.getActiveSheet().getActiveRange().getA1Notation();
    var getRow = ss.getActiveSheet().getActiveRange().getRow();  
    var sheetname = ss.getActiveSheet().getName();

    var user = Session.getActiveUser().getEmail();
    var Toemail = '....email address....';
    var subject = 'New Entry -' + ss.getName();
    var body = 'Your file has a new entry in - ' + sheetname + ' Updated by - ' + user + ' check file- ' + ss.getUrl(); 
    if(Number(ss.getActiveCell().getValue()!=-1.23456789) && getRow ==3) {
        MailApp.sendEmail(Toemail,subject, body);

    }

}; 

However, as I would like to find out which specific cell was changed and the new value, the updated script fails to save so I cannot run it. I guess the mistake is in var body, can anyone help?

function sendEmailAlert() {

    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var cellValue = ss.getActiveSheet().getActiveRange().getA1Notation();
    var getRow = ss.getActiveSheet().getActiveRange().getRow();  
    var sheetname = ss.getActiveSheet().getName();

    var user = Session.getActiveUser().getEmail();
    var Toemail = '...email address';
    var subject = 'New Entry -' + ss.getName();
    var body = 'Your file has a new entry in - ' + sheetname + ' Updated by - ' + user + ‘New Value in –‘ + cellValue + ‘= ‘ +ss.getActiveCell().getValue() +
    ' check file- ' + ss.getUrl();

    if(Number(ss.getActiveCell().getValue()!=-1.23456789) && getRow ==3) {
        MailApp.sendEmail(Toemail,subject, body);

    }
}; 

回答1:


You are right regarding that there is a problem on the var body code line: There are (curly quotes) instead of ' (straight quotes).



来源:https://stackoverflow.com/questions/56498642/notify-via-email-when-a-cell-is-updated-in-google-spreadsheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!