Home > Mobile >  How to enable other (non-registered) editors to use the Google Apps Script attached to a Google Shee
How to enable other (non-registered) editors to use the Google Apps Script attached to a Google Shee

Time:01-22

Hi fellow Stack Overflowers,

Yesterday I used Google Apps Script for the first time and I tried to hide certain rows given on user input. For me this works absolutely fine. Everybody else can access the sheet if they have the link to it and they are allowed to edit certain cells. Another user verified that he can access the Apps Script and as such that it actually is attached to the file, but the Apps Script does not seem to run for anyone else but me. '

function onEdit(e){
  if(SpreadsheetApp.getActiveSheet().getSheetName() == "Cooldown")
  {
    if (e.range.columnStart != 2 || e.range.rowStart != 5) return;
    else if(e.value != "TRUE")
    {
      SpreadsheetApp.getActiveSheet().hideRows(e.range.rowStart   1);
      SpreadsheetApp.getActiveSheet().getRange('B6').setValue(false);
    } 
    else SpreadsheetApp.getActiveSheet().showRows(e.range.rowStart   1);
  }
  else if(SpreadsheetApp.getActiveSheet().getSheetName() == "Benodigde Priesters")
  {
    if (e.range.columnStart != 2 || e.range.rowStart != 2) return;
    else if(e.value != "TRUE")
    {
      SpreadsheetApp.getActiveSheet().hideRows(e.range.rowStart   1);
      SpreadsheetApp.getActiveSheet().hideRows(e.range.rowStart   3);
      SpreadsheetApp.getActiveSheet().getRange('B3').setValue(false);
      SpreadsheetApp.getActiveSheet().getRange('B5').setValue(false);
    } 
    else 
    {
      SpreadsheetApp.getActiveSheet().showRows(e.range.rowStart   1);
      SpreadsheetApp.getActiveSheet().showRows(e.range.rowStart   3);
    }
    
  }  
}

As you might have noticed from the Apps Script, its intended purpose is to hide certain rows if a certain checkbox is unchecked and show the rows if it is checked. Rows 3 and 5 are hidden and B3 and B5 are reset to false if B2 is unchecked. Similarly, rows 3 and 5 are shown if B2 is checked.

Picture of the sheet

CodePudding user response:

You are saying that users are "allowed to edit certain cells". That implies that the sheets are protected.

The onEdit(e) function is a simple trigger that runs under the account of the user at the keyboard. If that user does not have the right to edit the columns that you are trying to hide, the function will throw an error when it tries to hide the columns. You can inspect the errors at My Executions.

To make it work, rename the onEdit(e) function to something like hideColumns(e) and use an installable "on edit" trigger to run it. Installable triggers run under the account of the user who set up the trigger.

  •  Tags:  
  • Related