I have a spreadsheet to track data, that every user with the link can edit. While I understand, that it is a security risk, I do not mind, because the spreadsheet is only kn
There are actually 2 onEdit triggers, the "simple" one and the "installable" one.
The simple onEdit runs as the user accessing the spreadsheet without asking for any authorization, that means it is unable to execute anything that requires authorization and using the SpreadsheetApp methods requires authorization (as you noticed when you ran that script yourself for the first time).
The installable triggers (onEdit, onChange, etc...) run as the author of the script , to be more accurate, they run as the user who installed the triggers.
They (the triggered functions) have the same "rights" as the user himself and can do everything the user can do.
Anonymous (not logged in) users that use the spreadsheet will trigger this script but they won't be responsible for what the script does and everything will be done in the name of the trigger "installer".
Feel free to try this spreadsheet where I wrote this script :
function onEdit(e) {
SpreadsheetApp.getActiveRange().setValue('simple onEdit Trigger running as sheet user without authorization');
}
function onEditInstallable(e) {
SpreadsheetApp.getActiveRange().setValue('Installable onEdit Trigger running as script author');
}
Please make also a copy of it after you tried and test that copy without installing any special trigger.
Then compare the results : in my sheet you'll get the message from the second function and in yours it will be the message from the first one.
When the installable trigger is active and you edit the sheet, both functions will be triggered and there is a chance that you actually see both texts successively since they generally don't take exactly the same time to run.
Anonymous user will always see the second one if you install a trigger in your sheet that calls the onEditInstallable
function onEdit
(from the script editor goto Ressources/current project triggers/create new trigger and select the one you need)
Documentation on that subject : simple triggers and installable ones