Evrim Yilmaz
Evrim Yilmaz

Reputation: 1

How can I let anonymous users to use onEdit()?

I have an Google Sheet that have 2 accessible columns for anonymous users. They will write a value on one column and they will select the "YES" as a confirmation of their input and that row will be hidden afterwards. I could achieve this but only for me. I know that simple onEdit function only works for admin but I couldn't change it to installable onEdit function. How can I do this or work around this?

/**
* TITLE:
*     Hide a row if a value is inputted.
*/
 
//**GLOBALS**
// Sheet the data is on.
var SHEET1 = "Oxford";
var SHEET2 = "Debrecen";
var SHEET3 = "Cluj-Napoca";
var SHEET4 = "UMH";
var SHEET5 = "RU";
var SHEET6 = "KI";
var SHEET7 = "BONN";
// The value that will cause the row to hide.
var VALUE = "YES";
// The column we will be using
var COLUMN_NUMBER = 8
 
function onEdit() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var activeSheet = ss.getActiveSheet();
  
  //Ensure on correct sheet.
  if(SHEET1 == activeSheet.getName() || SHEET2 == activeSheet.getName() || SHEET3 == activeSheet.getName() || SHEET4 == activeSheet.getName() || SHEET5 == activeSheet.getName() || SHEET6 == activeSheet.getName() || SHEET7 == 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);
      };
    };
  };
}

Upvotes: 0

Views: 304

Answers (1)

Wicket
Wicket

Reputation: 38200

This is wrong: "I know that simple onEdit function only works for admin ", the simple edit trigger works for any spreadsheet editor.

Share your spreadsheet to "anyone with the link" and set it to "Editor". Please bear in mind that anonymous users might need to use a Google Account to be able to edit the spreadsheet.

NOTE: The "anonymous" user should have signed in their Google account and should see the Share button

P.S. The cell edit history will show "All anonymous users" instead of the editor "anonymous" user.

References

Upvotes: 1

Related Questions