onEdit script does not start for users under anonymous access - google-apps-script

it's my 1st public question, hope I'm clear enough.
Here is the context:
I have created a spreadsheet as a template, including an "onEdit script"
I have made a copy of the spreadsheet created above, editable by everyone who has the link
when I open this copy and :
edit it, under my account (as owner), script works :)
edit it, under another google account script works :)
edit it, from an anonymous access, I can edit the sheet, but the script does not work :(
I have already read many posts like https://support.google.com/docs/thread/10422866?hl=en&msgid=10677830,
also tried this : https://support.google.com/docs/thread/41307278?hl=en&msgid=41569467. Got the same difference related to user access. :(
In fact, I need to share sheets with publics (without expecting Google account) and, because they are invited to, I need to determine which cells they may have edited.
Any idea will be greatly appreciated ! :)

Related

How to avoid saving a google sheet and have multiple people editing at the same time?

I’ve created a Google Sheet – kind of like an app – using script. It’s a number of blank cells where once added some information, it creates a string with that information in the right order. I created this to help some colleagues. We are using free accounts.
I face 2 problems:
The app is supposed to be used by only one person at a time, but I’m sure at some point two or more people will want to use it at the same time. Is there a way to allow this without they interfering with each other? I’ve read you can share a link that creates copies of your doc, but that wouldn’t work in this case because I intend to keep updating it regularly.
The changes people make to the sheet will stay there. Right now I have a onOpen function that just rewrites everything, but if someone accesses the document while someone is using it they’ll rewrite everything and ruin their work.
Any ideas on how to solve these two problems? Thank you so much in advance!
I think that you have to find another way to implement your "app" because Google Sheets not a good tool for limiting that only one user edit a spreadsheet a time, but if for any reason you decide to keep with it,...
... you need to implement a workflow like the following
Save the active user email on PropertiesService.getUserProperties().
This should be done by each user by running a script themselves. The most user-friendly will be by using a macro, custom menu or button (a drawing with an assigned Google Apps Script function). You might use an open installable trigger to validate that the active user have already done this.
You might have to make the function that clears the data a "smart" function.
You might have to consider additional cases, like if the owner of the spreadsheet opens it when there is an editor working on the spreadsheet.
Use installable triggers to manage the sharing settings.
Use an open trigger to remove all the editors except the active user
Use a time-driven trigger to add again the editors. To make this work effectively should define how the time-driven trigger will know that the last editor have finished their session, i.e. you might use DriveApp.getFileById(SpreadsheetApp.getActiveSpreadsheet().getId()).getLastUpdated()
The above should help you with both problems, as long you as the owner do not open the spreadsheet as is used by someone else.
Other alternatives that might work better is to create an add-on or a web application.
Related
Determine current user in Apps Script
Last modified date in Google App Script GAS sheets

Google sheet Script Permission to anyone

i have a google sheet , i wrote two scripts under it. one is "Dependent Dropdown" and another is for "Reset Data" to clear entries. Everything is working fine in my machine. script working ,dropdown also working with no issue.
but i have to share sheet with my colleague to edit this. i shared sheet with permission "Anyone with the link can edit".
now my colleagues can edit perfectly BUT those two scripts are not working.
do i have to set script permission ? or what? help please.
thanks in advance
unfortunately, that's the bottleneck of scripts - each colleague of yours needs to authorize the scripts otherwise they won't work for them.
there are installable triggers - https://developers.google.com/apps-script/guides/triggers/installable but user interference is still needed.
one way would be to create a shared account where scripts are authorized and then every user would use that account to access the spreadsheet

Script always active

Sorry if this was asked before but I could not find then answer.
I created a spreadsheet that is used by many users. It has an onEdit script. However it only works for me. Does every single user has to accept access for the script to change the spreadsheet?
The script will be run by and have the permissions of the owner that created the trigger to the script.
Ie if your account created the simple or installable trigger and steve opens the sheet, his actions will trigger the script to be run by your account.
None clear behavior that I have noticed that might explain what you are seeing:
- if lets say bob only has read only access or comment only access to the spread sheet no triggers will fire for his instance ( ie onopen() ).
Feel free to attach your full or a snippet of your code and trigger settings and someone should be able to assist in debugging.

Google script - Submit form response without having authorization to edit form

I have created a script for collaborators, to be used in google sheets.
When they trigger the script, it submits a form response, that then gets used to modify a "central" spread sheet.
But I am faced with a permission problem, and I haven't managed to find a convenient answer to it on the net.
The script uses FormApp.openById([...]).createResponse().[....].submit().
The problem comes from the fact both openById() and openByUrl() need the person who runs the script to be able to edit the form.
(As said on the Class FormApp help page : Returns the Form with the specified URL. Throws an exception if the URL is invalid or the user does not have permission to open the form.)
I have so far found 2 workarounds :
Give edit access for the form to my collaborators : it then shares them a form they shouldn't edit.
Change the link-sharing of the form to "on" : although no one but me actually knows the form Id, I don't really like the possibility of anyone discovering the link to be able to edit the form.
Neither of these workarounds completely satisfies me, and I'm sure there must be a way to submit a response via a script without being able to edit the form - just as people who send answers to google forms can't generally edit the questions ! Just I can't figure out how.
Any help on this problem will be very much appreciated !
Thank you,
Mike
Create a Web App using an account with owner or editor access to the form and set it to be run as the script owner. For a general guide see https://developers.google.com/apps-script/guides/web

Using Google Script in shared, restricted spreadsheets

I wrote a script for a google spreadheet which is run by clicking on an image embedded in the spreadsheet.
Everybody with the link to the spreadsheet can edit it (except some areas with formulas etc. which are protected).
When I'm logged in with my google account, everything works fine, but when I log out and try using the spreadsheet like a "normal" user, nothing happens when I hit the image.
I didn't find anything in the options regarding "script sharing" etc.
Would be awesome if someone could give me a hint (I'm quite new to google script...).
Thanks for your answers!
Vincent
Anonymous users can't run scripts. By design. Protected ranges, sharing and all the rest of it have nothing to do with your problem.
The user - whoever they happen to be - must be logged in to run any script. Scripts will simply be ignored for anonymous users.
So the solution in your case is to tell all your users that they must log in before being able to run a script.