Upload
william-chui
View
259
Download
3
Embed Size (px)
Citation preview
Google Apps Script
Arun [email protected]@entaq
What is 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.
1. Editor in a browser ○ zero install/setup, files stored, shared, versioned, managed in cloud
2. JavaScript runtime in the cloud ○ compliant, debuggable, and performant
3. Set of APIs and hooks to Google products ○ extend and enhance, built in security, distribution mechanisms
● Default Services are APIs that are built in to Apps Script● https://developers.google.com/apps-script/defaultservices
Default Services
What can Apps Script do?
Google Products
CalendarChartsContactsDriveDocuments DomainFinanceGmailGroupsLanguageMapsSitesSpreadsheets
Communication and UIContentHtmlJdbcMailSoapUiUrlFetchXml
Utilities
BaseCacheLockPropertiesScriptScriptDbUtilities
Supported Products and Features
○ Sending email○ JDBC ○ XML parsing○ SOAP○ Make HTTP requests with URLfetch○ Outbound OAuth support○ Build custom UIs○ Run a script as a service○ Script triggers○ Script and user properties
A Brief History
2009
2010
2011
2012
Scripts in SpreadsheetsCustom functions
UiAppWeb Apps (run as developer)Script Gallery
Scripts in SitesGUI BuilderMore services
Standalone scriptsHtmlServiceScriptDbWeb Apps (run as user)Libraries and versionsContent serviceChrome Web Store...
Google Confidential and Proprietary
What is Apps Script?function sendMap() { var sheet = SpreadsheetApp.getActiveSheet(); var address = sheet.getRange("A2").getValue(); var map = Maps.newStaticMap().addMarker(address); MailApp.sendEmail("[email protected]", "Map" ,map.getMapUrl());}
Google Confidential and Proprietary
What is Apps Script?function sendMap() { var sheet = SpreadsheetApp.getActiveSheet(); var address = sheet.getRange("A2").getValue(); var map = Maps.newStaticMap().addMarker(address); MailApp.sendEmail("[email protected]", "Map" ,map.getMapUrl());}
Google Confidential and Proprietary
What is Apps Script?function sendMap() { var sheet = SpreadsheetApp.getActiveSheet(); var address = sheet.getRange("A2").getValue(); var map = Maps.newStaticMap().addMarker(address); MailApp.sendEmail("[email protected]", "Map" ,map.getMapUrl());}
Google Confidential and Proprietary
What is Apps Script?function sendMap() { var sheet = SpreadsheetApp.getActiveSheet(); var address = sheet.getRange("A2").getValue(); var map = Maps.newStaticMap().addMarker(address); MailApp.sendEmail("[email protected]", "Map", map.getMapUrl());}
Google Confidential and Proprietary
Use Cases
Google Confidential and Proprietary
Use CasesGrading made easy with Flubaroo
● Create quiz using Google Forms● Automatically grades against answer key● Can email results and answers to each student● Provides charts to analyze the results
Google Confidential and Proprietary
Use CasesMany types of mail merge
● Define a simple template using a draft email, document, sites page, or spreadsheet cell
● Add placeholder values that should be dynamically replaced● Each spreadsheet row merged with template and sent out
Google Confidential and Proprietary
Use CasesVacation calendar for Brown University
● Aggregates together all the staff that are on vacation that day● Creates a single calendar event each day which lists everyone that
is out● Makes it easier to read your calendar
Google Confidential and Proprietary
Demo timeGMail Search
Simple app that allows users to search through their GMail.
Link
Source
Just open the script editor!
How do I get started?
● Standalone script● https://script.google.com● Google Drive > Create > More > Script
● Spreadsheet-bound script● Tools >Script Editor
● Sites-bound script● More > Manage Site > Apps Scripts > Add new script
● A trigger is a type of script resource that listens for a particular event and executes a function when that event fires.
● Simple triggers● Specially-named built-in functions that are specific to spreadsheets
● onEdit● onOpen● onInstall
● Installable triggers● Time-based triggers● Container-bound installable triggers (let's make one!)
https://developers.google.com/apps-script/understanding_triggers
Intro to Triggers
Apps Script
Creating an installable onEdit trigger// Create a script from a spreadsheet
// Create an onEdit trigger from the Resources > Current scripts triggers menu
// Type something in any cell other than A1
function setStatus(eventInfo) {
for (var e in eventInfo) {
Logger.log(e);
}
}
Apps Script
Saving data to ScriptDb
// Create this in a standalone script
function saveEmployee() {
var db = ScriptDb.getMyDb();
var employeeData = {type: "employee",
employee_id: 1,
first_name: "John",
last_name: "Testington",
department_id: 14};
var stored = db.save(employeeData);
Logger.log(stored.getId());}
Apps Script
Loading data from ScriptDb
// Add this below saveEmployee()
function loadEmployee() {
var db = ScriptDb.getMyDb();
var result = db.query({employee_id: 1});
while (result.hasNext()) {
var current = result.next();
Logger.log(current.first_name + ' ' + current.last_name);
}}
Google Confidential and Proprietary
How to get startedDocumentation
● http://developers.google.com/apps-script● User guide covering basic functionality● 30+ tutorials with code
Videos● YouTube channels GoogleDevelopers and GoogleApps
Stack Overflow● Tag questions with google-apps-script● Very active community, Google moderated
Google Apps Developer Blog
Script Gallery
<Thank You!>
What is Google Apps Script?