GAS onOpen() not running for copied spreadsheet - google-apps-script

I have a spreadsheet with a script that includes onOpen() which successfully creates some custom menus. When I copied the spreadsheet (and the bound script of course), the onOpen() no longer runs. I tried a few things I found from other postings of the same problem:
Revoke the new spreadsheet's authorization - can't because it does not show up in my account as an authorized app.
Manually create a trigger for when the doc opens - I get an error "We're sorry, a server error occurred. Please wait a bit and try again."
Copied the script file itself and renamed it.
Renamed the enclosing script project.
Renamed the enclosing spreadsheet.
So, none of these has worked. Anything else I can try, or is there a known problem on Google's side?
Thanks!

I looked at the said issue tracker and found that the problem stemmed from this line of code:
DriveApp.getFileById(SpreadsheetApp.getActiveSpreadsheet().getId());
To make this work, I would suggest to enable the Drive API in Resources -> Advanced Google Services. It will also ask you to enable Drive API in your Google Dev console. Do this and let me know if it worked for you.

Related

How can I bypass "Sign in with Google temporarily disabled for this app" in a Google Sheets script?

I'm attempting to use a script in a google sheet I've used in the past, and suddenly while trying to make a new sheet with this code, I'm getting a new error that is seemingly impossible to bypass.
"Sign in with Google temporarily disabled for this app
This app has not been verified yet by Google in order to use Google Sign In."
Normally, or at least every time I have used this script in the past, there has been an "advanced" and "continue anyway" option.
"This app isn't verified yet
"Advanced > Continue to Untitled Project (Unsafe)"
This is the code.gs script [gitlab link], how can I bypass this saftey check, and continue using this script as needed?
And for reference, these are the instructions for the whole project on git lab,
Unfortunately, there's no direct solution for the issue you are encountering.
According to the issue from Issue Tracker, the error you are encountering may be due to this cause:
an external user runs the script with sensitive scopes
A possible solution:
run the script from Incognito Mode and remove the project's permissions from myaccount.google.com/permissions
Ultimately, if this still doesn't solve your issue you can star the issue on Issue Tracker here.

Google App Scripts cannot be given Authorization or Permission

Why am I not able to give permission/authorization to a Google Apps Script that I also made using the same Google account?
It seems like Google doesnt trust myself to use my own Google Apps Script with my own Spreadsheet.
Here is the line of code that breaks everything. If this line doesnt exist, I'm not asked for permission.
var sheet = SpreadsheetApp.getActiveSheet();
So it's trying to access the spreadsheet that created this Google Apps Script, also made using my account but I cant grant permission.
When I run the line of code above, I am told I need to give permissions, so I do by selecting the account name I am already logged into. I am greeted by this error,
This app isn't verified
which unfortunately does not provide competent documentation to troubleshoot.
Any feedback or help would be much appreciated! Thanks!
Click on the "Advanced" link and you'll be able to authorize your script.
To reduce the scope of permissions you request, you also have the option of declaring your script project to be only able to interact with the bound document:
/* #OnlyCurrentDoc */
function myFunction() {
...
This declaration is incompatible with some methods (such as SpreadsheetApp.openById()), and using an incompatible method results in an error in the application execution.
Successfully adding it to your project is generally sufficient to remove the "This application is unsafe" layer of the authentication flow, meaning the authorization and permission list is not hidden behind the "Advanced" tab.
In addition to declaring as current document only, manually editing the requested scopes of your project in its project manifest can help reduce the perceived threat from an unverified application (for example, retaining only the "read_only" version of certain scopes, where applicable). Apps Script documentation offers more details on project manifests.

Google Scripts Error "You do not have permission to call toast"?

My coworkers started complaining today about problems they were having on a scheduling sheet that I automate with Google Scripts. I have not touched the code for this Spreadsheet for some time and was surprised to see the Stackdriver Logs full of errors:
You do not have permission to call toast at createJobFolder(Job_Files:112) at evaluateJobCode(Job_Code:29) at check(Triggers:14)
Did Google change anything about the permissions for .toast()? There was no new permission requests and I could not trigger one. Please advise.
Here is a quick way I have found to reproduce the error:
Paste the following code into the Script Editor:
function myFunction() {
SpreadsheetApp.getActive().toast('hello')
}
Run it to ok the permissions
Assign an edit event to it
Share it with another account and make an edit to reproduce the error.

All my news Google spreadsheets can't run a complex script

I've create a spreadsheet with a script for copy some other spreadsheet with a script inside, this worked fine for a moment.
But for several days all my scripts, on all news spreadsheets copied, they doesn't worked and they blocked when a complex line come (For example : DriveApp.getFileById(id))
(I say complex for script when onEdit, onOpen or other function can't run the line)
After somes researchs and reflexions, I think the problem come from the settings of my domain (G Suit), because when I use a new spreadsheet's script on an other account, they doesn't work, but if I use my old spreadsheet's scripts, they does work fine. I'm not sure.
The error messages I receive (it's when the script is out of time) are :
- An error has occurred on the server. We apologize and invite you to try
again later.
- Exceeded authorized execution time
I've tried to create a new spreadsheet and rewrite the script manually but I got the same error.
I'm not sure if it's only my domain, probably Google got some error too (But after 5 days it's strange).
Please, someone can help me, for say me if it's a problem with google, my domain or any other way.
(Sorry for my bad english)
Thanks in advance
Check the answer I've provided here.
You'll just have to enable Drive API for the project and from the Google Dev console.

Deleted script, no triggers, still getting emails

I deleted a google apps script from docs (Gmail Snooze), but I keep getting a message every day:
Start Function Error Message Trigger
6/9/12 12:49 AM myFunction We're sorry, a server error time-based
occurred. Please wait a
bit and try again.
I've already tried creating a new script, going to Resources > All Your Triggers, and nothing is there.
Is there a better way to get rid of these error messages than creating a new filter in gmail to auto delete them?
Have you also tried deleting the spreadsheet from the Trash in Google Docs?
There have been some reported problems around deleting triggers. You may want to add a comment on this open issue.
This worked for me!
Open a spreadsheet then go to tools-spreadsheet editor, then on the
editor window go to Resources->All your triggers... and see if the
trigger is still listed there. If so, delete it.
Source: How to delete a google apps script service
There might be an update to the interface. Triggers are now accessible trough different menu.
Open script.google.com and open any project or create a new one if you don't have any projects. Then go to Edit>All your triggers and switch off the ones you don't need.