GA add on - Automated run(Scheduled run) doesn't work - google-apps-script

I have a few automated reports on google sheets using the GA add on. Each of these reports have a number of sheets which need to be updated on an automated scheduled run (GA add on ->Scheduled run) .These were running just fine for until a couple of weeks back .
However, now,my automated reports wouldn't update the google sheets anymore unless I run it manually .
The manual updates seem to OK and the GA content loads just fine.
What could have gone wrong?
Thanks,

Sometimes it can happen, there can be several reasons (trigger conflict, authentication failure, etc ...) but they are not demonstrable since the errors are visible only by the owner of the add-on.
Try to uncheck schedule and save, put it back and save. If that doesn't work, copy your reports to a new Spreadsheet and activate the schedule there.

Related

Faulty Installed Clock Triggers on an Add-On

I designed a rather simple Add-On to enable my local team to more easily automate newsletters and target updates to Slack.
The Add-On works well, aside from two issues:
Schedule a send functionality.
I'm using the ScriptApp's newTrigger() function to allow users to schedule automatic sends.
While it seemed to have worked in original tests, the triggers are now triggering at the wrong time (a trigger that should run daily from 11-12AM has been running at 5PM - Another that should run at 6PM has been running at 12AM - I've checked and the timezones appear to be correct GMT+2 for Paris)
GetActive() returning the wrong sheet
This is a minor problem as I've only noticed it twice, but when running a script with getActive() from the correct sheet, it accidentally ran the script using another spreadsheet.
I remain at your disposal should you need any more information, IDs or the likes.
Thank you for any help and have a fantastic day

Turn OFF “Authorization is required” for Google Sheets Script for own team

We are a small company which just switched from paper to tablets (Surface GO Win10 Home) and we have one particular sheet which is used for every order (about 100 orders per month). This Google Sheet acts as a template for every single order and includes some easy code which is written in a bound Apps Script project, to handle things like switching the status from started to finished, copying some cells etc.
My problem is, when someone of the team wants to use the created "buttons" in the sheet to activate the script, it asks for authorization for the script the change the sheet. If you enable it, everything works fine but then for every new order you have to enable it again, and again, and it gets really annoying for every team member.
I tried somehow to
turn it off in the security options as administrator
tried it in the GOOGLE CLOUD PLATFORM under API's and services
tried to make the code somehow public in the script editor options
...but nothing seems not to work. I used VBA programs a lot in Excel VBA but it was more a hobby and I'm not a computer scientist, otherwise it would maybe be easier to solve this problem.
Is there an easy way so every one of my team can work with the sheets created out of a template without any request from Google for authorization every time.
Kind regards.
The reason for the popups is that Google Apps Script is not part of Google Sheets itself, it's a separate application that uses OAuth 2.0 to get the permissions to make the requests by calling the APIs. The popup shows the scopes you are authorizing for. This means that you can't disable that.
Note that apps script could do more things that just edit the spreadsheet itself; it could get other files, get your personal information, call external servers, etc. Also, the authentication process will only happen once per file.

Can not run trivial app script bound to new blank document - get "This app is blocked"

I am unable to run any app script in my google account - even one created by me bound to a new document created by me. When I do, I get an "This App is Blocked" error. Note that this is different from the the "Sign in temporarily disabled for this app" failure mode mentioned elsewhere, and the solution for that problem has no effect on this one.
To test, I created a new spreadsheet while logged into my personal google account and put the value ONE in cell A1...
I then opened the Tools->Script editor from the menu bar of this spreadsheet and entered the following trivial script...
I then click on the run icon from the script editor menu bar with the function "myFunction" selected from the pulldown.
I get an "authorization required" popup and so I click "Review Permissions"...
I then get a "Choose an account" popup and click on my account (the only logged in account, and the same account I was logged into when I created the sheet and the script)...
I then get an "App Blocked" popup. Checking the execution log shows that the script did not run.
What is causing this popup and how can I prevent this so I can run app scripts?
NOTE: I see many other questions describing more complicated versions of this issue but none have useful answers. I am hoping this ultra simple version of the issue will help narrow it down and get a resolution.
More unexpected behavior:
If I put the code into the onLoad() function it works fine and never even asks me for authorization.
If I enter this code:
...and then quit out and reload the sheet, then I get this in the execution logs...
Again, this is with no authorization popups at all. The sheet loads without interruption and then the entry is in the execution logs. So this would seem to not be a case of not having the right permissions somewhere since code clearly can access the sheet.
Legacy editor
Identical behavior under the legacy editor...
Other accounts
I can repeat these exact same steps on a different google account and it works fine, so this problem appears to be linked to my account. Many others on the internet have noted the same finding. Seems like there might be some hidden (probably unintional) setting attached to the account that gets switched somehow and then thereafter the account is not able to manually authorize scripts to run.
Changing Project
I check and this script is in the "Default" project as expected...
According to this page,
For most applications and scripts, you never need to see or adjust this default GCP project—Apps Script handles all the necessary interactions with the Google Cloud Platform automatically.
Since I have nothing to lose, tried creating a new project in the Google Cloud Platform console, and then tried assigning this script to that new project. Unfortunately when I tried, I got the normal "Authorization needed" popup which lead to this opdd page...
Clicking on the "Troubleshoot this problem" link takes me to this page...
...which seems to say that I do not have the permissions to troubleshoot problems on my own account.
This again seems to suggest there is something misconfigured about my account on google servers. :/
Unfortunately there are no good answers there. Lots of people like me wake up one random morning to find that they can not run any new App Scripts in their account any more.
I've found a workaround that works great... but will make you very sad.
This issue does not affect code that runs automatically, so functions like onOpen() and onEdit() run just fine and have full access to the bound document. You heard that right- google blocks code that the user explicitly requests to run to protect their data, but code that runs silently and automatically anytime a sheet is opened or modified is free to run and access (and change!) whatever data it wants.
So to let the user run your code, you pick a cell inside the spreadsheet that either has a value that changes whenever you want your code to run, or you make a special cell called "Edit this cell to run the program".
Then you put your code inside the onEdit() and (if desired) check to see to see if the special cell was updated. If so, then run your arbitrary code. It has full access to the spreadsheet and can read and update cells at will and can also write to the log.
Note that you must close the sheet and re-open it for the code to take effect.
Here is what my demo spreadsheet looks like...
...and here is the demo code...
function onEdit(e) {
var range = e.range;
const triggerCell = "B2";
if( e.range.getA1Notation() === triggerCell){
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
var rangeB1 =sheet.getRange("B1");
var rangeB2 =sheet.getRange("B2");
var date = Utilities.formatDate(new Date(), Intl.DateTimeFormat().resolvedOptions().timeZone, "HH:mm:ss");
rangeB2.setValue("Code ran at " + date );
Logger.log( date + ": B1=" + rangeB1.getValue() );
}
}
Here is a demo video...
https://youtu.be/ypuLaUWn1R8
I've said it before, I'll say it again - if you were thinking about using Google Cloud Services for anything then think again. This is crap built on top of crap that no one at google understands and it occasionally breaks suddenly and catastrophically, and there is no one who can even tell you what is going on much less how or when or if it is going to get fixed.
I ran into this for the first time today but my issue seems to be due to:
created a sheet on a shared drive owned by a different organization
my organization uses the legacy apps script interface, the shared drive organization uses the new apps script interface
Using an account from the shared drive organization to create the script solved my issue.
This error
This app is blocked
seems to be a new error affecting certain Google accounts. This is reported to Google. Kindly star(add a star ★ to it on top left) to the following issues and comment to get Google developers to prioritize this issue:
https://issuetracker.google.com/issues/176138626
https://issuetracker.google.com/issues/181220763
Some workarounds:
#15 Creating a new GCP and linking it.
#12 Turning on Less Secure Apps
#10
Checking accounts security page
Turning off advanced protection
Unlock Captcha
This issue does NOT seem to be related to another issue 145162820:
"Sign in temporarily disabled for this app"
The error messages are different.

Unable to authorize ANY external Google Apps Script scope on any ANY file [duplicate]

I am unable to run any app script in my google account - even one created by me bound to a new document created by me. When I do, I get an "This App is Blocked" error. Note that this is different from the the "Sign in temporarily disabled for this app" failure mode mentioned elsewhere, and the solution for that problem has no effect on this one.
To test, I created a new spreadsheet while logged into my personal google account and put the value ONE in cell A1...
I then opened the Tools->Script editor from the menu bar of this spreadsheet and entered the following trivial script...
I then click on the run icon from the script editor menu bar with the function "myFunction" selected from the pulldown.
I get an "authorization required" popup and so I click "Review Permissions"...
I then get a "Choose an account" popup and click on my account (the only logged in account, and the same account I was logged into when I created the sheet and the script)...
I then get an "App Blocked" popup. Checking the execution log shows that the script did not run.
What is causing this popup and how can I prevent this so I can run app scripts?
NOTE: I see many other questions describing more complicated versions of this issue but none have useful answers. I am hoping this ultra simple version of the issue will help narrow it down and get a resolution.
More unexpected behavior:
If I put the code into the onLoad() function it works fine and never even asks me for authorization.
If I enter this code:
...and then quit out and reload the sheet, then I get this in the execution logs...
Again, this is with no authorization popups at all. The sheet loads without interruption and then the entry is in the execution logs. So this would seem to not be a case of not having the right permissions somewhere since code clearly can access the sheet.
Legacy editor
Identical behavior under the legacy editor...
Other accounts
I can repeat these exact same steps on a different google account and it works fine, so this problem appears to be linked to my account. Many others on the internet have noted the same finding. Seems like there might be some hidden (probably unintional) setting attached to the account that gets switched somehow and then thereafter the account is not able to manually authorize scripts to run.
Changing Project
I check and this script is in the "Default" project as expected...
According to this page,
For most applications and scripts, you never need to see or adjust this default GCP project—Apps Script handles all the necessary interactions with the Google Cloud Platform automatically.
Since I have nothing to lose, tried creating a new project in the Google Cloud Platform console, and then tried assigning this script to that new project. Unfortunately when I tried, I got the normal "Authorization needed" popup which lead to this opdd page...
Clicking on the "Troubleshoot this problem" link takes me to this page...
...which seems to say that I do not have the permissions to troubleshoot problems on my own account.
This again seems to suggest there is something misconfigured about my account on google servers. :/
Unfortunately there are no good answers there. Lots of people like me wake up one random morning to find that they can not run any new App Scripts in their account any more.
I've found a workaround that works great... but will make you very sad.
This issue does not affect code that runs automatically, so functions like onOpen() and onEdit() run just fine and have full access to the bound document. You heard that right- google blocks code that the user explicitly requests to run to protect their data, but code that runs silently and automatically anytime a sheet is opened or modified is free to run and access (and change!) whatever data it wants.
So to let the user run your code, you pick a cell inside the spreadsheet that either has a value that changes whenever you want your code to run, or you make a special cell called "Edit this cell to run the program".
Then you put your code inside the onEdit() and (if desired) check to see to see if the special cell was updated. If so, then run your arbitrary code. It has full access to the spreadsheet and can read and update cells at will and can also write to the log.
Note that you must close the sheet and re-open it for the code to take effect.
Here is what my demo spreadsheet looks like...
...and here is the demo code...
function onEdit(e) {
var range = e.range;
const triggerCell = "B2";
if( e.range.getA1Notation() === triggerCell){
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
var rangeB1 =sheet.getRange("B1");
var rangeB2 =sheet.getRange("B2");
var date = Utilities.formatDate(new Date(), Intl.DateTimeFormat().resolvedOptions().timeZone, "HH:mm:ss");
rangeB2.setValue("Code ran at " + date );
Logger.log( date + ": B1=" + rangeB1.getValue() );
}
}
Here is a demo video...
https://youtu.be/ypuLaUWn1R8
I've said it before, I'll say it again - if you were thinking about using Google Cloud Services for anything then think again. This is crap built on top of crap that no one at google understands and it occasionally breaks suddenly and catastrophically, and there is no one who can even tell you what is going on much less how or when or if it is going to get fixed.
I ran into this for the first time today but my issue seems to be due to:
created a sheet on a shared drive owned by a different organization
my organization uses the legacy apps script interface, the shared drive organization uses the new apps script interface
Using an account from the shared drive organization to create the script solved my issue.
This error
This app is blocked
seems to be a new error affecting certain Google accounts. This is reported to Google. Kindly star(add a star ★ to it on top left) to the following issues and comment to get Google developers to prioritize this issue:
https://issuetracker.google.com/issues/176138626
https://issuetracker.google.com/issues/181220763
Some workarounds:
#15 Creating a new GCP and linking it.
#12 Turning on Less Secure Apps
#10
Checking accounts security page
Turning off advanced protection
Unlock Captcha
This issue does NOT seem to be related to another issue 145162820:
"Sign in temporarily disabled for this app"
The error messages are different.

How to get a notification if Google Script's "My Executions" shows that a script hasn't run in specified time

I have a Google Script running every 5 minutes. It works except randomly there are sudden crashes and the script/trigger won't survive that. So, for many different reasons, the script stops running after some weeks of continuing runtime. At this point, I would need a notification.
How can I get a notification if a function (script) hasn't run in say 2 hours? Doesn't matter what the technique/notification is, but probably email would be great for the notification. I don't think the solution can be in the script code itself, because the script randomly (every few weeks) crashes at Google's side and there's nothing I can do about that.
Google Apps Script installable triggers automatically set an email notification. You could edit when it should be sent (i.e. send immediately) and you could add more notifications. NOTE: This can only be done manually.
The above will work for "normal" failures but it there is a service outage or other platforms failures the notification might not be sent.
One option is to log the executions somewhere then set a second trigger to check that the first trigger ran every time that it should do it as expected. NOTE: The failure that prevented that the first trigger run might also prevent that his second trigger run i.e. a service outage so you might want to set other monitoring measures accordingly the the severity/priority of this failure and your project budget.