Introduction to Scripting
 | Apps Scripting allows power users to extend the features and
functionality of Google Tools. Use Scripts with Forms, Spreadsheets,
Calendars and Sites to automate tasks, gather and distribute information
and control workflow.
Google Apps Scripts are written in
Javascript. Although this is not a difficult language to learn, the
good news is there are many scripts already written and tested for you to use. In most cases, all you have to do is copy and paste the script and perhaps change an address or document ID and you are ready to use the script. The goal for today is to get you comfortable finding and configuring scripts. Enjoy!
|
Apps Scripts are based on Javascript. The basic components of Javascript are:
- Functions- What do you want to do (launch an application, submit a form)
- Variables- What information will help you do it (email addresses, numbers, formulas)
- Triggers- When do you want something to happen (when the page loads?, when you click a button?)
- Methods- Where do you want it to happen (new window?, application?, new UI?)
| This is a sample spreadsheet script that appends the spreadsheet with "mail sent" when another script sends the user notification when they fill out a form. The first part identifies a global variable called "EMAIL_SENT". Then in the function, variables are set for the sheet to use, the rows to use and then the "for" statement basically says look at the spreadsheet and if certain conditions exist in it (i.e it has been populated with some data) then fire up the "MailAPP" and make a new entry in column "C" of the spreadsheet and put "Email Sent" in it so you know who has been contacted. |
Scripting ResourcesThis is a partial list of resources (there are dozens more!) to get you started with tutorials and places to find more scripts to work with! - Apps script tutorials from Google Developers site
- Apps scripting news from the Google Developers blog
- An older, but still informative video introduction to Google Apps Scripting
- Apps Script Tutorials from Waqar Ahmad
Inserting ScriptsThe basic steps for inserting a script are pretty simple. You are going to do it one of 3 ways. | 1. Insert an existing script from the gallery |  From the Spreadsheets menu | | 2. Insert a script in the script editor (copy and paste) | | | 3. Authorization |
|
Gotchas and Best Practices- Do NOT copy and paste scripts from one file to another out of the script editor. The triggers are set per file and the script will break in the new file. Open the new file, go get the original script and paste it in. If you wrote the script in the editor yourself, you will have to reset all of the triggers yourself in the new file.
- Scripts that are copied from third party sources such as developer websites will not automatically authorize. This is simply the process where Google tells you bad things can happen with bad scripts and then forces you to allow it anyway... If you don't authorize the script you will get a message where your script is supposed to be that tells you the script must be authorized. To authorize a third party script, simply run it in the script editor. This will force the authorization box to open and then the script will run.
- Some scripts give you the option of running only as you, or allowing any user to run them. This is simply from the administrative level. Essentially, any script you insert should only be set to run by you. Users will still be able to use the script, but they will not be able to EDIT it.
- If you are using Apps in Ed and scripting, you are probably in a firewalled environment. TEST, TEST, TEST. Sometimes scripts are blocked by firewalls. If you can't get a script to work and you have otherwise followed all the steps, test it outside the firewall and see if it works.
- Big scripts crunching lots of data can choke a network. Run them at off hours.
|
|