简体   繁体   中英

Automatically move row based on cell data

I have the following code:

function onEdit(event) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = event.source.getActiveSheet();
  var r = event.source.getActiveRange();

  if(s.getName() == "Out" && r.getColumn() == 10 && r.getValue() == "TRUE") {
    var row = r.getRow();
    var numColumns = s.getLastColumn();
    var targetSheet = ss.getSheetByName("Returned/Billed");
    var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
    s.getRange(row, 1, 1, numColumns).moveTo(target);
    s.deleteRow(row);
  }
}

What I'm trying to do is to remove the entire row based on the answer in column 10, or J. Once it is removed from sheet "Out", I need to have it added to sheet "Returned/Billed". What I don't get, is it was working when I first added this code. But now it's not working.

I do have this spreadsheet linked to a AppSheet app that only I have access to and use. But when I change column 10/J to TRUE, it's not making the change.

I also got this email last night from Google:

Start   Function    Error Message   Trigger End
4/3/17 8:27 PM  onEdit  TypeError: Cannot call method "getActiveSheet" of undefined. (line 3, file "Code")  time-based  4/3/17 8:27 PM

How do I get this to run properly so I can use the app I created?

Thanks in advance!

most AppSheet questions are asked and answered at http://community.appsheet.com

To your question, it sounds like you want to have an onEdit trigger fire on the spreadsheet as a result of an update captured via the AppSheet app. Unfortunately, this will not work. You will need to use a timed trigger instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM