How to set a trigger when a close button is pressed on the spreadsheet.
is it actually possible?
The script I am using is google apps script
It is not possible. See here a list of triggers available on Google Scripts.
Related
In Google Scripts I'm trying to use a on form submit trigger, but all I see in events are Time-Driven and From Calendar
The project must be bound to the Google form or to the connected spreadsheet for the onFormSubmit trigger to be available in the triggers UI.
Open your Google form
Click Tools > Script editor from within the form
I want to run a Google App Script function every time a change is made to my Google Doc. I have found onChange and onEdit triggers which are only available for Google Spreadsheet. I am sure there must be an edit/change trigger for Google Doc as well.
Unfortunately there are no onEdit(), onChange() triggers for Google Docs.
The triggers available for Google Docs are the following:
onOpen() triggers both simple and installable;
time driven triggers;
onInstall() simple triggers.
What you can do instead is to use a time driven trigger so in this way even though the changes are not directly triggering the execution, the trigger will still run how often you want it to.
Last but not least, you can file a Feature Request on Issue Tracker where you specify the details needed.
Reference
Apps Script Trigger;
Google Issue Tracker.
I would like to catch an event once a row is added to a google sheet (via google forms) using google script api , is it possible ?
My Spreadsheet has multiple sheets but i am only interested on the rows added to a specific sheet.
Thank you
Short answer
If you are using the built-in feature to send responses from a Google Form to a Google spreadsheet, use the on form submit event.
Explanation
The Google Sheets API doesn't have event triggers, only Google Apps Script. By the other bear in mind that the installable trigger on change is triggered only by changes made by the "user on keyboard".
References
https://developers.google.com/apps-script/guides/triggers/
https://developers.google.com/apps-script/guides/triggers/events
I am looking to locally use a Google Apps Script with one of my Google Sheets (Attached to a form) that will be accessible to all emails that have permission to access the sheet, but I don't plan on publishing this script to the public. Do I still need to publish in order to use this script, or will I be fine just adding an onSubmit function for my Google Form as a trigger for my script to run in my Google Sheet? And can I use installable triggers if I plan on operating this script as a standalone only attached to this one Google Sheet?
Do I still need to publish in order to use this script
No: If you own the spreadsheet (or have editor permissions on it), your script can remain private. A script does not need to be bound to a Spreadsheet except if it will use:
Spreadsheet UI (getUi(), custom menus, dialogs and sidebars)
"Active" items (getActiveSpreadsheet(), getActiveSheet(), getActiveRange(), getActiveCell())
...will I be fine just adding an onSubmit function for my Google form as a trigger for my script to run in my Google Sheet?
Yes: Your standalone script can have installable triggers associated with Google Apps items such as spreadsheets, documents and forms.
And can I use installable triggers if I plan on operating this script as a standalone only attached to this one Google Sheet?
Yes: There's nothing special about the 1:1 relationship; the same trigger could be installed for multiple spreadsheets.
Phrased another way, is there a way to:
Create a new Google Spreadsheet (from the Google Drive API)
And then create a Google Apps Script associated with that Google Spreadsheet programmatically
And then programmatically activate the "On Edit" and "On Form Submit Triggers" to call various methods in the script? (this is the part I cannot figure out)
-OR- (as #JacobFlatter suggested)
Manually create a spreadsheet with the desired script
Use the Google Drive API to programmatically copy the spreadsheet (which copies with script with it as well)
Somehow programmatically activate the "On Edit" and "On Form Submit Triggers" (which DO NOT copy over from copying the spreadsheet, this is the part I cannot figure out)
Possible path to follow:
Create a container bound script with an onOpen() trigger within a spreadsheet.
Copy the existing Spreadsheet (which will copy the script as well) programmatically.
Open the new Spreadsheet programmatically (unsure if this will initiate the trigger described above).
This assumes a few things, but seems like it is worth investigating. I'm curious if this works. Good Luck.
Unfortunately, no. You cannot do meta programming with Apps Script.
Based on the answer to this question, I wrote a simple function to try meta programming
function meta(){
var mime = 'application/vnd.google-apps.script';
DocsList.createFile('MetaScript','function test(){}', mime);
}
It throws up an error saying Invalid mime type