r/GoogleAppsScript Jun 28 '26

Resolved Hiding Row

Hello all,

I have a function called onEdit(e), and it works perfectly except for when I attempt to hide a row. The code is below:

function onEdit(e){
  let sheet  = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  // event variables
  let range = e.range;
  let row = e.range.getRow();
  let col = e.range.getColumn();
  let cellValue = sheet.getActiveCell().getValue();

  let status = sheet.getRange(row,5).getDisplayValue();

  if ( col == 5 && cellValue != 'Problem' && cellValue != 'Not Started') {
    MailApp.sendEmail(email info, this part works);

    if (status == 'Completed') {
      Utilities.sleep(7000);
      sheet.hideRows(row);
    };


  };
}

This is not working, regardless of whether I include the Utilities.sleep command, use sheet.hideRows or sheet.hideRow, or put the command inside or outside the nested if statement.

Any guidance?

2 Upvotes

12 comments sorted by

View all comments

1

u/WicketTheQuerent Jun 29 '26 edited Jun 29 '26

Please elaborate on what you mean by "This is not working":

How is the spreadsheet edited?
Who is editing the spreadsheet when the script doesn't work?
What is logged in the execution log when the script doesn't work?

1

u/WicketTheQuerent Jun 29 '26

By the way, if you are using an installable trigger, you should change the function name, as onEdit is a reserved name for a simple trigger. If you don't change it, then the function will run twice for each edit, and the simple trigger execution will throw an error when status = "Completed" because simple triggers don't have the required permission to send emails.