I've been struggling for two days now to allow the users from my organization to edit the protected pieces of a spreadsheet using only the script I made.
I've been through hell and how I made it work in the end is, I made a fake hidden sheet where the data is stored, and then onOpen, I copy-paste that data to the sheet that the user sees (that they cannot edit). I want to make the UX a bit better if possible, and I was hoping there is a way to force the onOpen trigger from the script. I know I probably didn't do this right, but I cannot spend more time researching, so I need to brute-force it now. (I've tried onChange triggers, I've tried setting permissions in my web app, using doPost, and my brain hurts, this is the first time I'm doing scripting).
TL;DR Is there a way to refresh the whole tab from the script editor? I need to trigger the onOpen event without the user having to reload the page.
CodePudding user response:
To "force" the onOpen simple trigger you have the following options
- call onOpen
If your onOpen function requires the event object you will have to emulate it.function respondToChange(e){ onOpen(); }
function respondToChange(e){ const event = {}; // add the required properties to event onOpen(event); }
- change the spreadsheet locale by using
setSpreadsheetLocale
Related
CodePudding user response:
When a function is run by clicking a button or choosing a custom menu item, or through a simple trigger such as onOpen(e)
or onEdit(e)
, it runs under the account of the user at the keyboard.
To trigger a function to run under another account that has rights to the protected ranges, you need an installable trigger.