0

I have a "hide sheets" function. I've tried using it as an onOpen function, and also with a On Open trigger.

It works fine if an Editor opens the GS.

But if a Viewer opens the GS, it doesn't work at all. If it's an On Open trigger, I get an error email that "Authorization is required to perform that action." If it's called as an onOpen function, it just doesn't work, but also doesn't generate any errors.

Is there a way to make this work for Viewers?

Rubén
  • 34,714
  • 9
  • 70
  • 166
Edward Wu
  • 463
  • 4
  • 13
  • `onOpen` trigger should not perform sensitive actions, at most create a menu. Also, why did you expect a function that modifies spreadsheet structure to work for users who only have read-only access? If you *absolutely* necessary have to hide it from viewers, add them temporarily to editors list and remove once done. But a better flow would be to *show* additional sheets to users who have sufficient permissions, not the other way around – Oleg Valter is with Ukraine Aug 06 '20 at 01:58

2 Answers2

3

Viewers can't execute scripts including those called by simple triggers like onOpen

One option among many others is to have one spreadsheet for editors and another for viewers then somehow send the changes made by the editors to spreadsheet shared with viewers.

Related

Rubén
  • 34,714
  • 9
  • 70
  • 166
2

Consideration

onOpen trigger should not perform sensitive actions, at most create a menu.

A simple trigger won't be able to run under this low privileged scope (viewer-only).

A better flow would be to show additional sheets to users who have sufficient permissions, not the other way around.

Reference

Triggers Restrictions

Alessandro
  • 2,848
  • 1
  • 8
  • 16