Creating a task scheduler in GAS? - google-apps-script

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

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)

Do Google Calendar Triggers execute in order?

I run a google calendar trigger for every user (10k users) which notifies some external resources when something changes in the users calendar.
However I have some issues because it seems like the triggers don't always execute in order. When for example one user moves an event several times in a second it could be that the notification to an external resource of the last event movement hits first before the others do.
When I look into the Google Stackdriver logging I also could see that the same behavior when logging the trigger. But of course the issue could also be the logger itself.
How can I fix this when my business logic relies on the correct order of changes for a calendar? I know that there is also the Push Notification for Calendar but there is no watch for a single calendar and this will also mean that I need to watch 10k of users which I don't think it's very practical.
So how can I solve this? Or am I wrong about the trigger execution order and the problem lies on the external resources execution order of requests?

How can I add an event trigger that fires when a contact is edited, created or deleted in my Google Contacts account?

I am making a Google Sheets Spreadsheet that needs to have all of my contacts from my account, up to date with any changes that are made. Outputting to the Spreadsheet is the easy part, but I can't find resources in the Google API Reference nor in Stack Overflow (except for this post from 5 years ago) referencing such an
'onContactUpdated()' trigger.
This leads me to believe that such a trigger doesn't actually exist, which I think is peculiar, considering the Calendar API has an already integrated trigger that comes with the base Apps Script experience:
ScriptApp.newTrigger('functionName').forUserCalendar('userEmail').onEventUpdated().create();
Did I just miss it? Does it exist? If so, how can I create one?
And in case one doesn't exist, what other solution can you guys recommend to me? The contact list is already 400 contacts long, and it is expected to keep growing over time. I don't know of a way in which I could just keep polling in a time-based manner that would keep the list up-to-date without getting ever so close to exceeding the 90min total daily runtime quota.
Any solutions would be greatly appreciated.
Thanks in advance,
Felipe Santini.
Short Answer:
No, there is no event object for Contacts API or People API.
Long Answer:
You still need to poll your contacts list for any changes using a time-based trigger. Your polling frequency depends on your need and the limitation of the daily runtime quota. To save runtime, you could poll changes only for specific fields instead of checking everything.

How can I modify a trigger so that it emails upon edit, but not so quickly?

I have a script that creates additional files upon submission of a Google Form. It also sets up a trigger for said new document, so that people are emailed when any edits are made to the document after its creation, e.g.
ScriptApp.newTrigger("sendEmailOnModification")
.forSpreadsheet(SpreadsheetApp.openById(fileId))
.onEdit()
.create();
The logic all works, but... the trigger is extremely sensitive. Every time someone makes a single keystroke in the document, it fires. It doesn't make a lot of sense to repeatedly fire as someone writes a paragraph; it makes more sense to, say, fire 10 minutes after the last edit. (Or something. Anything that doesn't spam emails.)
Is there a way to modify the trigger so that it fires less often (I do not want a time-based trigger), or otherwise programmatically change how frequently Google Sheets saves?
As a last resort, I suppose I could create a hidden sheet that captures last modified time and a condition not to send an email if subsequent modifications are less than X minutes ago, but that's kind of clunky and not really appealing. Hoping I can do it entirely in Google Scripts instead.
You could use the Properties Service to save a timestamp of the last time that the email was sent and compare it to the actual time of the current execution.
I'm not sure how you could implement this to suit your needs,but since you don't want a time based trigger, and you are already using onEdit(), you should be able to use
onEdit(e) and e.oldValue to check if the change is worth the message.

How to use a second (minute or hour is to long for immediate response) based trigger?

I am writing an immediate response code in google script which must monitor inbox at current time and if it detects a new e-mail with given subject then it runs the code and replies to the e-mail and at the end it marks the e-mail as read.
The whole stuff works fine, however I want it to get started more frequently than once in a minute. Thus I guess I can't use trigger option from the scripts interface. Will it work if I won't specify a trigger? How can I organize all this? I am using this stuff with google free quota for my personal use only.
thanks beforehand
Its not advisable to do what you want because you will run out of quota.
But its possible. Not with triggers as they run at most once a minute.
If you must, write a htmlservice app with a setInterval. Call a server method to do your work. Leave the webapp open all day.