0
votes

I am running the following script as its own .gs file

/** 
* TITLE:
*     Hide a row if a value is inputted. 
*/
//**GLOBALS**
// Sheet the data is on.
var SHEET = "Norm Adam";
// The value that will cause the row to hide. 
var VALUE = "Yes";
// The column we will be using 
var COLUMN_NUMBER = 11

function onEdit(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var activeSheet = ss.getActiveSheet();
  
  //Ensure on correct sheet.
  if(SHEET == activeSheet.getName()){
    var cell = ss.getActiveCell()
    var cellValue = cell.getValue();
    
    //Ensure we are looking at the correct column.
    if(cell.getColumn() == COLUMN_NUMBER){
      //If the cell matched the value we require,hide the row. 
      if(cellValue == VALUE){
        activeSheet.hideRow(cell);
      };
    };
  };
}

It works fine on a computer browser but on iOS device it doesn't work through the google sheets app and I actually can't even get the editable through safari. I read that only the onEdit function will work on a mobile device so I figured this should work. Is there another piece to this puzzle? Thanks Mike

(credit for script creation goes to: https://yagisanatode.com/2018/05/26/how-to-hide-a-row-based-on-a-cell-value-in-google-sheets-with-filter-or-google-apps-script/ )

Script V2: I commented below on this still not working in iOS. I figured the simpler it was the more likely to work?

function onEdit(e) {  
    if (e.range.getColumn() == 11 && e.value == 'Yes') {  
        e.range.getSheet().hideRows(e.range.getRow());
    }
}
1
Could you add console.log("this script executed") inside that script? And see if a edit in iOS app triggers it in tools>script editor>view>stackdriver logging? - TheMaster
Hi, thanks for the tip. I added console log and did some testing. It appears that the script is only running when editing the google sheet via desktop machine. When I try to edit via iOS google sheets app, the change appears on the desktop but the log indicates that no executions have been triggered. - Michael Emond

1 Answers

0
votes

getActive calls, especially ss.getActiveCell() should be avoided on mobile apps. Consider alternatives like e.range to get the edited range from event objects.