Finding Row Number of a change made via changetype = other

251 views Asked by At

I need to be able to call the row number where a change was made, when changeType == "OTHER". Below is a test script (with runNotify triggered via on change) that should email me the row number of the row where the change was made, however it only ever returns "1" as the row number. What am I missing that keeps it from returning the row number of the changed row?

function notify(request) {
    MailApp.sendEmail("youremailhere.com", "Row Added", request.editedRow);
}

function runNotify(e) {
  var range = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("Y:Y");
    if (e.changeType == "OTHER") {
    var request = findRow(e);
    notify(request);
    }
}

function findRow(e) {
  var range = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("Y:Y");
    if (e.changeType == "OTHER") {
    this.editedRow = range.getRow();
    return this;
  }
}

Working code that will call the row being edited following a change made in App Script when used with onChange trigger:

function notify(request) {
    MailApp.sendEmail("[email protected]", "Row Added", request.activeRow);
}

function runNotify(e) {
    if (e.changeType == "EDIT") {
      var request = findTheRow(e);
      notify(request);
    }   else {
      return;
      }
}

function findTheRow(e) {
  var sSht = e.source;
  var sht = sSht.getActiveSheet();
  var activeRng = sht.getActiveRange();
  this.activeRow = activeRng.getRow();
  return this;
}

1

There are 1 answers

0
Shane Campbell On

Code that will return the number of the edited row when a change is made via AppSheet:

function notify(request) {
    MailApp.sendEmail("[email protected]", "Row Added", request.activeRow);
}

function runNotify(e) {
    if (e.changeType == "EDIT") {
      var request = findTheRow(e);
      notify(request);
    }   else {
      return;
      }
}

function findTheRow(e) {
  var sSht = e.source;
  var sht = sSht.getActiveSheet();
  var activeRng = sht.getActiveRange();
  this.activeRow = activeRng.getRow();
  return this;
}