- What can an App Script do and why would I want to use one?
App Scripts (scripts) are little bits of code that help automate a lot of tasks within the Google Drive ecosystem. One example of a very common use of App Scripts is for running tasks after a Google Form is submitted, like emailing the submitter based on their answers or performing bookkeeping on the form's spreadsheet of data.
Google Forms is somewhat limited in the operations it can do, especially compared to the old College of Engineering forms system, and App Scripts allows you to get some of that functionality back.
- How can I add a script to an existing form?
Because of how scripts work you'll need to attach the script to either the form itself or the spreadsheet of responses. Scripts are always attached to the document, form, etc. that they work on. Attaching the script to the form itself is a good idea if you just need to do something like send customized email receipts based on the data of the person who just submitted the form. Attaching the script to the spreadsheet would be a better idea if you need to perform actions on previous submissions as well. You might need to explicitly create the spreadsheet of responses in your form.
Once you decide where your script should be attached you simply create it in the main view for the document: click "Tools" -> "Script Manager" -> "New"
- How can I let someone else write the script for me and then transfer ownership back to me?
To share the script is to share either the form or response spreadsheet that the script is attached to. Doing this is simple - open up the document and click "Share" and enter the person's umich email address to give them edit permissions for the document. From inside the document they should be able to edit the script as well.
A word of caution, though: any triggers the new editor creates (see below) will continue to run as long as that person is an editor of the document and will be totally unavailable to you (the owner) to change without removing the new editor's permissions. A good practice is to have your editor write the code but do the triggers yourself.
- Why isn't my script working?
There's no catch-all answer to this question but here are a few places to start. By far one of the most common problems people have when working with scripts is that the scripts fail to run due to insufficient privileges - for example, if you want a script to send email (as you) you must explicitly give it permission or the script will fail. To check for this try running the function you're working on from within the script editor - if additional permissions are needed a prompt will pop up and ask you to give them.
Another place to look is in the execution transcript inside your script editor. It should keep a track of the last execution of your script and, if it failed, where it failed. This data is collected and sent out at the end of the day in a report to the script owner's email address. You can change the frequency of this email if you want, all the way up to having it alert you as soon as your script fails.
- How can I transfer ownership of my form (with scripts) to someone else?
If you want to permanently transfer ownership of your form, with it's scripts to someone else, the only thing to really worry about are the triggers in your form (see below). Because your triggers are only viewable and editable by you, the new owner may have triggers being fired in your script that they don't have control over. Because of this it's important to remove any triggers you added to the script before transferring ownership and having the new owner re-add the triggers. Apart from this, just share the form (and spreadsheet, if applicable) as you would any other Google document.
Triggers are events related to the Google document you've attached your script to that allow you to have a function in your script automatically fire when certain things happen. A good example of this is the onSubmit trigger for Google Forms - whenever your form is submitted you can have a piece of code in your script run.
Triggers are tricky because to make use of because they're attached to a specific person as well as the document - for example, two different people could have an onSubmit trigger for the same form, meaning that two pieces of code will be run whenever the form is submitted. Your scripts can be viewed, added to, and managed from within the script editor: go to "Resources"->"Current Project's Triggers"
- Why can't I see triggers that I know are there or are still firing?
Triggers are specific to a person and a document, meaning that only a person can see and edit their own triggers. If a trigger is firing that you can't see (for example, you keep getting an email whenever you submit a form) you should contact the other people with edit permissions for that form to see who owns that trigger.
- What are some resources to help me write scripts?
- App Script Tutorials
- Forms-specific Tutorials
- Forms Service Docs
- Spreadsheet Service Docs
- How to send an email on form submit