0

I need help with a code.

I need to get a notification on my email or Slack when for example, column D changes. But I would love to received what column changed.

Here is what I got right now.

function sendEmailAlert() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();

  var sheetname = ss.getActiveSheet().getName();
  var user = Session.getActiveUser().getEmail();
  var cell = ss.getCurrentCell()
  var col = cell.getColumn();
  var row = cell.getRow();
  
  var Toemail = '************@gmail.com';
  var subject = 'New Entry -' + ss.getName();
  var body = 'Cambio de DSID- '

  
  if(col === 2) {
    MailApp.sendEmail(Toemail,subject, body);
 }

};

how can I add knowing what changed?

1
  • Hi! Take the tour here. How often do you think your spreadsheet will be edited? Appscript has a daily quota limit of 100 emails per day so if editing is frequent, then you're better off not using email. I can't think of a possible alternative though
    – David Tan
    Jun 7 at 0:41

1 Answer 1

0

"But I would love to received what column changed."

Since your IF statement (if(col === 2) {) is watching Column B, perhaps you mean that you would like to know what row changed, &/or the cell address, &/or the old value, &/or the new value.

  • If you want to keep the function name of sendEmailAlert then create a installable onEdit trigger. Otherwise, rename the function to onEdit and it will automatically execute as a simple trigger.

  • Include an argument to pass the Event objects - for example onEdit(e).

  • Use the event objects to to extract the relevant information. For example.

    Logger.log("the edited cell = "+e.range.getA1Notation())
    Logger.log("the old value = "+e.oldValue)
    Logger.log("the new value = "+e.value)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.