Creating personal tutoring environments with Google Apps Script
Introduction to Google Apps Script
-
Upload
martin-hawksey -
Category
Education
-
view
3.265 -
download
10
description
Transcript of Introduction to Google Apps Script
Introduction to Google Apps ScriptOn form submit filter data to sheets
Martin Hawksey@mhawksey
The Problem
Hi there, I'm trying to get some student PT's to complete a training diary using a Google form.
I would like the form to automatically create a new sheet for each user. I should ultimately have 42 entries per user/sheet.
http://www.google.com/support/forum/p/Google+Docs/thread?tid=6fe8356595e9b859&hl=en
http://mashe.hawksey.info
Solution 1 - Filter the data
http://mashe.hawksey.info
Solution 2 – Google Apps Script
• Google Apps Script is a JavaScript cloud scripting language that provides easy ways to automate tasks across Google products and third party services.
http://code.google.com/googleapps/appsscript/
http://mashe.hawksey.info
How I see it
http://mashe.hawksey.info
How you write it
http://mashe.hawksey.info
• In Spreadsheets– Tools > Script Editor
• In Sites– Manage Site > Apps Script
How does the user interact with it
http://mashe.hawksey.info
• In Spreadsheets
• In Sites
• As a service
There’s good and bad news
http://mashe.hawksey.info
• Bad news– You need basic programming skills to write
• Good news– Already a growing number of developers
publishing scripts and tutorials for you to reuse e.g. http://www.flubaroo.com/
Lets do it
http://mashe.hawksey.info
https://spreadsheets.google.com/a/hawksey.info/spreadsheet/ccc?key=0Alq6_NgDnxLWdENvZHhwVm93TjRhTm5fcjU0X0t3Vnc
Logins: [email protected]@hawksey.info …[email protected]
Password: *******
Explanation of Javascript Objects got by getValues()
Dog Cat Cow
22 31 15
6 5 5
data = [[“Dog”,”Cat”,”Cow”],[22, 31, 15],[6, 5, 5]]
data[0] = [“Dog”,”Cat”,”Cow”]
data[0][1] = “Cat”
http://mashe.hawksey.info
Useful links
http://mashe.hawksey.info
• Workshop material from Open4Ed– http://mashe.hawksey.info/2011/05/app-app-and-
away-workshop-handout-open4ed-gas/• Simple Apps Solutions (free Apps Script
consultancy for Ed and tutorials)– http://simpleappssolutions.com
• Official Apps Script Site– Docs– Tutorials– Help forum
Not forgetting your friendly EdTech explorer
http://mashe.hawksey.info
• Email: [email protected]• Blog: http://mashe.hawksey.info• Tweet: @mhawksey
Pseudo-code
// onFormSubmit // get submitted data // check if username has sheet // if not make // copy submitted data to user's sheet
http://mashe.hawksey.info
Final code
function onFormSubmit() { // onFormSubmit // get submitted data var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheetByName("Form_Sheet"); var headings = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues(); var lastRow = sheet.getRange(sheet.getLastRow(), 1, 1, sheet.getLastColumn()).getValues(); var studentUsername = lastRow[0][1]; // check if username has sheet if(ss.getSheetByName(studentUsername)){ var userSheet = ss.getSheetByName(studentUsername); // if not make } else { var userSheet = ss.insertSheet(studentUsername); userSheet.getRange(1, 1 , 1, headings[0].length).setValues(headings); } // copy submitted data to user's sheet userSheet.getRange(userSheet.getLastRow()+1, 1, 1, lastRow[0].length).setValues(lastRow);}
http://mashe.hawksey.info