Faulty Installed Clock Triggers on an Add-On - google-apps-script

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

Related

How to implement? Spreadsheet with link - Go To Link Grab Data - Update Spreadsheet Row

I am looking for technology suggestions. Or if this can be done in native google sheets (note the site I am looking to access is behind a username and password).
I have a google sheet that looks like this
birth date
link
data_element_from_website
12/31
https://something.com/3920230
1/31
https://something.com/1920238
lets say on https://something.com/3920230 there is a HTML element 123
Twice a day I want to be able to refresh the data, this could be done by going into the spreadsheet and clicking/doing something.
Can this be done?
What if https://something.com/3920230 is behind a login (authentication). Note: I could be logged in to the website in a different tab... I don't think that would make a difference though...
Assuming you have a script that you would like to run twice a day, you can use Apps Script Time-driven triggers:
A time-driven trigger (also called a clock trigger) is similar to a cron job in Unix. Time-driven triggers let scripts execute at a particular time or on a recurring interval, as frequently as every minute or as infrequently as once per month. (Note that an add-on can use a time-driven trigger once per hour at most.)
If it's just some formulae, you can change the recalculation settings to be either On change, On change and every minute or On change and every hour under the File > Spreadsheet settings menu item and clicking on the Calculation tab.
If you want to get data from public site(no login) you can use ImportXML. You can google a lot about it, for example
https://answerbun.com/personal-finance-money/get-revenue-details-in-google-sheets-using-google-finance/
If the page you want can only be accessed using login, this becomes a rather complicated task, especially using only apps script libraries (not much scraping lib support here)

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

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.

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.

Creating a task scheduler in GAS?

So I'm just getting back into scripting with GAS and I'm trying to make a scheduler/reminder system for tracking periodic maintenance that has to be done.
The idea is a form that fills info to a spreadsheet (easily done), and then iterate through the sheet and create events on a dedicated calendar for every 'job', with recurrence set to how often the job needs doing. ie: every 3 months, clean the drains.
I have this part of it working. What I'm wondering is... is it possible to have a script call a function at a specified date and time? Like instead of a calendar event that emails you a reminder about the event on the day of (or whenever), maybe call a function so that I can email them some details about the job (again, pulling from the sheet, which is simple enough) and maybe throw it at Pushbullet API to push to the user's phone/browser. I've played with PB's api, and everything, the ONLY part of this that I don't have working is the scheduled future script firing.
If this isn't possible, would anyone be able to recommend an alternative?
Edit: For clarification, I'd be wanting to set up a one-time execution of a function on say ... June 14th. In terms of recurrence, I can just have it set the next scheduled run during the execution.
If I understood correctly, you need to use the Trigger!
Yes, it’s possible. Use time-driven triggers. For details see https://developers.google.com/apps-script/guides/triggers/installable

GAS: deploy time based trigger app

I wrote a custom GAS that reads some emails and manipulates them. It uses the time based trigger to run. I want to know if there is a way to "deploy" a specified version of this where the time based trigger still runs, but I can still work on new code changes in the apps script editor (running it manually) and then deploy that new version (that runs by time triggered) when it is ready?
You might want to look into add-ons:
https://developers.google.com/apps-script/add-ons/