0
votes

I have the following spreadsheet:

-Template (protected)

-Current working sheet

-older sheet (protected)

-even older sheet (protected)

This spreadsheet is shared with a few users, and they have write permission in the "current working sheet". Once it is considered completed, I created a button in the "current working sheet" to which I assigned a script. When ran as owner, the script:

  1. renames the "current working sheet" to "something older"
  2. protects the "something older" sheet
  3. duplicates the "template" sheet as a new "current working sheet"

It all works fine wen ran by owner, however when the button that triggers the script is pressed by one of the users whom I shared the document with, then step (2) fails, meaning the sheet can't be protected. I suspect this is a permissions issue but I am a complete newbie in google scripting, so I am asking for some help here. Is there any way to make sure that no matter who presses the button, the assigned script is ran as owner?

thank you

1

1 Answers

1
votes

You cannot have a button which the user at the keyboard clicks invoke a script which runs as the owner. See the doc about authorization here. That said, what you can do is have the button set a value or update a record which a script on a time based trigger checks. A flow like this would work well:

  1. User updates the working sheet
  2. User clicks the I am done! button
  3. Script adds a row to a hidden sheet called Things for scripts to do which indicates that as of now, the working sheet should be archived
  4. Every hour, a script checks Things for scripts to do and updates sheets and permissions as described above