I am using a script which is found here: https://moz.com/ugc/updated-tool-seomoz-api-data-for-google-docs
I would like to trigger this to run once an hour (as a test, later once a month); to facilitate this I set up a time driven trigger in the script editor UI.
I need to test that the trigger is actually working. The issue is that I do not expect any of the data to change when the script runs (might change once a month max)...
So I looked to the script editor and found View > Execution Transcript. Perfect!
Except that I get this message:
No execution transcripts found. Please run your script and try again.
This doesn't seem to be consistent with the expected behaviour after reading the Google Apps Script documentation page, which says:
Every time you run a script, Google Apps Script records an execution
transcript, which is a record of each call to a Google Apps Script
service that is made while the script runs.
(Nothing in the logs either by the ways, though maybe this is something that needs to be turned on by the script itself; not sure).
So how can I test to see that my time driven trigger works, and that the script is being run each hour?
Final note: The script is executed by calling a function in the spreadsheet, as explained in the link at the top of the question.
If you have not yet run it manually, there may be an issue with it being given the proper permissions. Your first step would be to run the code manually using the play button. Once you know that the code itself will run successfully and has the right permissions, you can move to triggering it automatically.
Your next step is to shorten your trigger time so that it executes more frequently giving you more instances to check the function. Depending on the structure of your code, you can add Logger.log() calls at different steps to make sure that all portions are being called that need to be. You can then check you logs instead of the execution transcript as well.
These Logger.log() calls could include the time at which is was called to be able to verify that it was at the time/ frequency you need.
Ok, I don't know how great this answer is... but:
For me (as per my comment to MasterCrander), running the script by means of using the function inside the spreadsheet didn't actually affect the execution transcript, but when it ran via the time driven trigger it made it into the transcript.
Problem solved.
Related
When developing Google Apps Scripts (specifically for Sheets in my case), you can use the Debug button to step through code and inspect variables, or you can use the Logger to output debug info.
What I can't figure out, however, is if there is any way to do these things when functions are triggered through the sheet itself. For example, from a custom menu item which fires a function, or an onEdit() trigger.
It makes it very difficult to debug issues because, as far as I can tell, GAS simply fails silently. Nothing useful appears in the browser JS console either.
I'm writing this answer as a community wiki, since the issue was resolved from the comments section, in order to provide a proper response to the question.
As mentioned in the comments, you can use the Apps Script execution log in the script editor. You can use either the Logger or console logging service.
In addition, to test a trigger function and check if there are any errors, you can do the following:
Since you're using onEdit trigger, edit a cell in the sheet.
Go to the Apps Script project.
If there are errors, you can view the logs in the "Executions" section and you'll find a list of executions which you can filter by Failed and Time out.
Reference:
Apps Script mechanisms for logging
I have a google script presently that uses the basic time-based triggers, and runs once a day. The code works and the trigger runs when it is supposed to, but I want to enhance my script to run when a file is uploaded to my drive. Right now, I use a lot of logic to determine if any file has been uploaded since the last run, but I really want to get it so that the script runs if a file has been uploaded.
My question is, is that possible, and if so, can someone direct me to some links on how to make this a reality?
Thanks,
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.
I have a script in a google spreadsheet which changes the activated cell.
I you have selected A1 for example the script activates A3.
If you run it again it selects A5 and so on.
This is what it should do.
Now I want the script to be run timer-based in foreground.
I installed a trigger for that but the script only runs in background when started by the trigger.
Background is that I have a PC running, showing an overview list.
This List has now grown to be longer than the Monitor can display.
So I want the PC to automatically scroll through the document let's say one step every minute.
I could do it with an iteration but that would stop the script after the execution time out of 6 minutes while the script should run about 8h a day.
Any ideas how to solve this problem?
Don't use GAS for this. It runs server side with it's non-adjustable constraints.
Use something like an automator which will simulate keyboard commands. You can script it client side, by sending the "down" button to scroll through your list. Check "Autoit" for windows.
not possible using triggers as they can only perform server side work.
the only possible way with apps script is to open a sidebar from onOpen and use setInterval to keep calling your server function.
this also consumes less time quotas as most of the time is spent from clientside than relying on the 6minute server limitto keep updating state.
I have a few scripts that I want to run overnight so I've set up script triggers to execute these. Its all pretty straightforward stuff and they run fine. But occasionally, say once a month, one of them fails to execute. No error messages are sent to me by Google or anything like that.
Has anyone else experienced this? Has anyone got any ideas I can check for this error? Obviously if its the actual trigger that's not firing in the first place then the code won't actually run and therefore it won't be able to run any checks.
I'll also flag this with Google themselves in google-apps-script-issues forum.
I have a trigger set to fire every five minutes and a few times a month it will fail. Often it will say something about the function not being found.
You can be notified of an execution failure by setting up an "execution failure notice". In Resources > Current Script's Triggers, after each trigger will be a "notifications" link. Clicking it will open the "Execution failure notifications" window.
You have some choices about timing of the email notification of the failure.
Maybe: I suspect that, after I edit my code, sometimes the triggers miss fire. But I have never double checked this.
Suggestions:
1) add some logging and at the end of the script, grab the log and email it back to yourself.
2) Add a try catch around your code and email any errors that you catch back to yourself.
Google scripts are throttled in various ways and your script may be hitting up against one of these limits. There are limits on the number of emails you can send and limits on execution time of the script in addition to others.