SlideShare a Scribd company logo
1 of 23
Download to read offline
Enterprise Workflow with
            Apps Script
                    Claudio Cherubino
       Google Apps Developer Relations

           http://plus.claudiocherubino.it
What is Apps Script?

 ● JavaScript engine in the cloud
    ○ JavaScript Runtime
    ○ Write and execute code in browser

 ● Comes with
    ○ JavaScript syntax and classes
    ○ Built-in access to various Google APIs
    ○ Ability to integrate 3rd party services
Why Apps Script?




           Don't hate, automate
Where is Apps Script?

 ● Executed in a variety of different ways
    ○ Spreadsheet, Sites, Standalone, Async
Who can use Apps Script?
Apps Script Services




            Don't hate, automate
A basic example



   // Function to convert from inches to centimeters
   function in2cm(inNum) {
      var outNum = 0; // this will hold the result
      var factor = 2.54; // multiply input by this factor
      if (typeof inNum != "number") {
          return("error: input must be a number");
      }
      outNum = inNum * factor;
      return outNum;
   }
Let's write some code...
Read the content of a Google Doc


  function main() {
    var documentId = '18ByAQxeL...';
    var letter = DocumentApp.openById(documentId);

      var subject = letter.getName();
      var message = readDocumentBody(letter);
  }

  function readDocumentBody(document) {
    var paragraphs = document.getParagraphs();
    var txt = "";

      for (var i = 0; i < paragraphs.length; i++) {
         if (paragraphs[i].getNumChildren() > 0) {
             txt += paragraphs[i].getChild(0).getText();
         }
         txt += "n";
      }
      return txt;
  }
Retrieve stock information



 function main() {
    var documentId = '18ByAQxeL...';
    var letter = DocumentApp.openById(documentId);

      var subject = letter.getName();
      var message = readDocumentBody(letter);

      // retrieve GOOG stock price
      var stockInfo = FinanceApp.getStockInfo('GOOG');
      var stockPrice = Math.round(stockInfo.price * 100) / 100;
      var stockValue = stockPrice + ' ' + stockInfo.currency;

      // replace placeholder with current stock value
      message = message.replace('[STOCKVALUE]', stockValue);
  }
Process users from spreadsheet



 var sheet = SpreadsheetApp.getActiveSheet();
 var startRow = 2; // First row of data to process
 var numRows = sheet.getLastRow() - 1; // Number of rows to process

 var dataRange = sheet.getRange(startRow, 1, numRows, 4);
 var data = dataRange.getValues();

 for (i in data) {
    var row = data[i];
    var name = row[0];
    var emailAddress = row[1];
    var language = row[2];
    var location = row[3];

      // personalize letter with shareholder's name
      var text = message.replace('[SHAREHOLDER]', name);
  }
Automatically translate messages



  for (i in data) {
     var row = data[i];
     var name = row[0];
     var emailAddress = row[1];
     var language = row[2];
     var location = row[3];

      // personalize letter with shareholder's name
      var text = message.replace('[SHAREHOLDER]', name);

      if (language != 'en') {
          text = LanguageApp.translate(text, 'en', language);
      }
  }
Send mail from a script



  for (i in data) {
     var row = data[i];
     var name = row[0];
     var emailAddress = row[1];
     var language = row[2];
     var location = row[3];

      // personalize letter with shareholder's name
      var text = message.replace('[SHAREHOLDER]', name);

      if (language != 'en') {
          text = LanguageApp.translate(text, 'en', language);
      }

      MailApp.sendEmail(emailAddress, subject, text);
  }
Add markers to Google Maps


 var map = Maps.newStaticMap().setSize(1024, 1024);
 for (i in data) {
    var row = data[i];
    var name = row[0];
    var emailAddress = row[1];
    var language = row[2];
    var location = row[3];

     // personalize letter with shareholder's name
     var text = message.replace('[SHAREHOLDER]', name);

     if (language != 'en') {
         text = LanguageApp.translate(text, 'en', language);
     }

     MailApp.sendEmail(emailAddress, subject, text);
     map.addMarker(location);
 }

 var mapUrl = map.getMapUrl();
More examples...
Calendar API


   // get user's calendar
   var calendar = CalendarApp.getDefaultCalendar();

   // schedule event
   var startDate = new Date();
   var endDate = new Date(startDate);
   endDate.setHours(startDate.getHours()+2);

   var event = calendar.createEvent(
     "Training:",
     startDate,
     endDate,
     {description:"Training event"});
3rd-party APIs



   // function to access Netflix API
   function searchNetflixTitles(genre, startPosition, numberOfResults) {
       var ODATA_GENRE_URL = "http://odata.netflix.
 com/Catalog/Genres";

       var requestURL = ODATA_GENRE_URL + "('" + genre + "')/Titles?"
           + "$select=Name,ShortSynopsis&$format=json&$skip="
           + startPosition + "&$top=" + numberOfResults;

       var content = UrlFetchApp.fetch(requestURL);
       var result = Utilities.jsonParse(content.getContentText());
       return result;
   }
Ui Services


  // create List Box Message Label
  var listBoxMessageLabel = app.createLabel()
       .setText("1. Choose the Training Category:");
  decorateLabel_(listBoxMessageLabel);

  // create List Box
  var categoryListBox = app.createListBox()
       .setName("categoryListBox")
       .setId("categoryListBox");
  categoryListBox.addItem("Category List", "0");
  categoryListBox.addItem("Language Instruction", "1");
  categoryListBox.addItem("Computers & Electronics", "2");
  decorateLabel_(categoryListBox);

  // create change handler
  var categorySelectHandler =
       app.createServerChangeHandler("categorySelectionHandler_");

  categorySelectHandler.addCallbackElement(mainPanel);
  categoryListBox.addChangeHandler(categorySelectHandler);
Charts Services - 1/2



  function getData() {
   // populate the DataTable. We'll have the data labels in
   // the first column, "Quarter", and then add two data columns,
   // for "Income" and "Expenses"List Box Message Label
   var dataTable = Charts.newDataTable()
       .addColumn(Charts.ColumnType.STRING, "Quarter")
       .addColumn(Charts.ColumnType.NUMBER, "Income")
       .addColumn(Charts.ColumnType.NUMBER, "Expenses")
       .addRow(["Q1", 50, 60])
       .addRow(["Q2", 60, 55])
       .addRow(["Q3", 70, 60])
       .addRow(["Q4", 100, 50])
       .build();

      return dataTable;
  }
Charts Services - 2/2


  function buildChart(dataTable) {
   // Build the chart. We'll make income green and expenses red
   var chart = Charts.newColumnChart()
      .setDataTable(dataTable)
      .setColors(["green", "red"])
      .setDimensions(600, 400)
      .setXAxisTitle("Quarters")
      .setYAxisTitle("$")
      .setTitle("Income and Expenses per Quarter")
      .build();

      return chart;
  }

  function main() {
    var chart = buildChart(getData());
    var ui = UiApp.createApplication();
    ui.add(chart);
    SpreadsheetApp.getActiveSpreadsheet().show(ui);
  }
Triggers

 ● Trigger ~= Event handler

 ● Triggers allow asynchronous execution of
   scripts
    ○ Helps in automation
    ○ A user no longer has to manually execute the script

 ● Two Types of Triggers
    ○ Event Driven - onEdit, onInstall, onOpen
    ○ Time Driven
Resources

 ● Apps Script documentation
    ○ http://code.google.com/googleapps/appsscript/

 ● Tutorials
    ○ http://code.google.com/googleapps/appsscript/articles.html

 ● Online community
    ○ http://www.google.com/support/forum/p/apps-script/

 ● Google Apps Script Blog
    ○ http://googleappsscript.blogspot.com/
Thanks!

Questions?


@ccherubino
http://plus.claudiocherubino.it

More Related Content

What's hot

EclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseEclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
Heiko Behrens
 
MDSD for iPhone and Android
MDSD for iPhone and AndroidMDSD for iPhone and Android
MDSD for iPhone and Android
Heiko Behrens
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1
saydin_soft
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
偉格 高
 

What's hot (19)

6. CodeIgniter copy2
6. CodeIgniter copy26. CodeIgniter copy2
6. CodeIgniter copy2
 
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseEclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
 
MDSD for iPhone and Android
MDSD for iPhone and AndroidMDSD for iPhone and Android
MDSD for iPhone and Android
 
How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1
 
Selenium cheat sheet
Selenium cheat sheetSelenium cheat sheet
Selenium cheat sheet
 
Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots
 
Source Code for Dpilot
Source Code for Dpilot Source Code for Dpilot
Source Code for Dpilot
 
this
thisthis
this
 
library(sparkline)
library(sparkline)library(sparkline)
library(sparkline)
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
Chaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscoreChaining and function composition with lodash / underscore
Chaining and function composition with lodash / underscore
 
SOLID in Practice
SOLID in PracticeSOLID in Practice
SOLID in Practice
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applications
 
Javascript essential-pattern
Javascript essential-patternJavascript essential-pattern
Javascript essential-pattern
 
Lodash js
Lodash jsLodash js
Lodash js
 
Solid in practice
Solid in practiceSolid in practice
Solid in practice
 
Using Scala Slick at FortyTwo
Using Scala Slick at FortyTwoUsing Scala Slick at FortyTwo
Using Scala Slick at FortyTwo
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascript
 

Similar to Enterprise workflow with Apps Script

Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicate
Kiev ALT.NET
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
rajivmordani
 
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Roel Hartman
 

Similar to Enterprise workflow with Apps Script (20)

Dartprogramming
DartprogrammingDartprogramming
Dartprogramming
 
Cnam azure 2014 mobile services
Cnam azure 2014   mobile servicesCnam azure 2014   mobile services
Cnam azure 2014 mobile services
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
 
Java Script Best Practices
Java Script Best PracticesJava Script Best Practices
Java Script Best Practices
 
Week 12 code
Week 12 codeWeek 12 code
Week 12 code
 
To-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step GuideTo-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step Guide
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicate
 
Broadleaf Presents Thymeleaf
Broadleaf Presents ThymeleafBroadleaf Presents Thymeleaf
Broadleaf Presents Thymeleaf
 
GDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptxGDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptx
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
GWT
GWTGWT
GWT
 
Gooogle Web Toolkit
Gooogle Web ToolkitGooogle Web Toolkit
Gooogle Web Toolkit
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
I Phone On Rails
I Phone On RailsI Phone On Rails
I Phone On Rails
 
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
 
Zend framework service
Zend framework serviceZend framework service
Zend framework service
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 

Enterprise workflow with Apps Script

  • 1. Enterprise Workflow with Apps Script Claudio Cherubino Google Apps Developer Relations http://plus.claudiocherubino.it
  • 2. What is Apps Script? ● JavaScript engine in the cloud ○ JavaScript Runtime ○ Write and execute code in browser ● Comes with ○ JavaScript syntax and classes ○ Built-in access to various Google APIs ○ Ability to integrate 3rd party services
  • 3. Why Apps Script? Don't hate, automate
  • 4. Where is Apps Script? ● Executed in a variety of different ways ○ Spreadsheet, Sites, Standalone, Async
  • 5. Who can use Apps Script?
  • 6. Apps Script Services Don't hate, automate
  • 7. A basic example // Function to convert from inches to centimeters function in2cm(inNum) { var outNum = 0; // this will hold the result var factor = 2.54; // multiply input by this factor if (typeof inNum != "number") { return("error: input must be a number"); } outNum = inNum * factor; return outNum; }
  • 9. Read the content of a Google Doc function main() { var documentId = '18ByAQxeL...'; var letter = DocumentApp.openById(documentId); var subject = letter.getName(); var message = readDocumentBody(letter); } function readDocumentBody(document) { var paragraphs = document.getParagraphs(); var txt = ""; for (var i = 0; i < paragraphs.length; i++) { if (paragraphs[i].getNumChildren() > 0) { txt += paragraphs[i].getChild(0).getText(); } txt += "n"; } return txt; }
  • 10. Retrieve stock information function main() { var documentId = '18ByAQxeL...'; var letter = DocumentApp.openById(documentId); var subject = letter.getName(); var message = readDocumentBody(letter); // retrieve GOOG stock price var stockInfo = FinanceApp.getStockInfo('GOOG'); var stockPrice = Math.round(stockInfo.price * 100) / 100; var stockValue = stockPrice + ' ' + stockInfo.currency; // replace placeholder with current stock value message = message.replace('[STOCKVALUE]', stockValue); }
  • 11. Process users from spreadsheet var sheet = SpreadsheetApp.getActiveSheet(); var startRow = 2; // First row of data to process var numRows = sheet.getLastRow() - 1; // Number of rows to process var dataRange = sheet.getRange(startRow, 1, numRows, 4); var data = dataRange.getValues(); for (i in data) { var row = data[i]; var name = row[0]; var emailAddress = row[1]; var language = row[2]; var location = row[3]; // personalize letter with shareholder's name var text = message.replace('[SHAREHOLDER]', name); }
  • 12. Automatically translate messages for (i in data) { var row = data[i]; var name = row[0]; var emailAddress = row[1]; var language = row[2]; var location = row[3]; // personalize letter with shareholder's name var text = message.replace('[SHAREHOLDER]', name); if (language != 'en') { text = LanguageApp.translate(text, 'en', language); } }
  • 13. Send mail from a script for (i in data) { var row = data[i]; var name = row[0]; var emailAddress = row[1]; var language = row[2]; var location = row[3]; // personalize letter with shareholder's name var text = message.replace('[SHAREHOLDER]', name); if (language != 'en') { text = LanguageApp.translate(text, 'en', language); } MailApp.sendEmail(emailAddress, subject, text); }
  • 14. Add markers to Google Maps var map = Maps.newStaticMap().setSize(1024, 1024); for (i in data) { var row = data[i]; var name = row[0]; var emailAddress = row[1]; var language = row[2]; var location = row[3]; // personalize letter with shareholder's name var text = message.replace('[SHAREHOLDER]', name); if (language != 'en') { text = LanguageApp.translate(text, 'en', language); } MailApp.sendEmail(emailAddress, subject, text); map.addMarker(location); } var mapUrl = map.getMapUrl();
  • 16. Calendar API // get user's calendar var calendar = CalendarApp.getDefaultCalendar(); // schedule event var startDate = new Date(); var endDate = new Date(startDate); endDate.setHours(startDate.getHours()+2); var event = calendar.createEvent( "Training:", startDate, endDate, {description:"Training event"});
  • 17. 3rd-party APIs // function to access Netflix API function searchNetflixTitles(genre, startPosition, numberOfResults) { var ODATA_GENRE_URL = "http://odata.netflix. com/Catalog/Genres"; var requestURL = ODATA_GENRE_URL + "('" + genre + "')/Titles?" + "$select=Name,ShortSynopsis&$format=json&$skip=" + startPosition + "&$top=" + numberOfResults; var content = UrlFetchApp.fetch(requestURL); var result = Utilities.jsonParse(content.getContentText()); return result; }
  • 18. Ui Services // create List Box Message Label var listBoxMessageLabel = app.createLabel() .setText("1. Choose the Training Category:"); decorateLabel_(listBoxMessageLabel); // create List Box var categoryListBox = app.createListBox() .setName("categoryListBox") .setId("categoryListBox"); categoryListBox.addItem("Category List", "0"); categoryListBox.addItem("Language Instruction", "1"); categoryListBox.addItem("Computers & Electronics", "2"); decorateLabel_(categoryListBox); // create change handler var categorySelectHandler = app.createServerChangeHandler("categorySelectionHandler_"); categorySelectHandler.addCallbackElement(mainPanel); categoryListBox.addChangeHandler(categorySelectHandler);
  • 19. Charts Services - 1/2 function getData() { // populate the DataTable. We'll have the data labels in // the first column, "Quarter", and then add two data columns, // for "Income" and "Expenses"List Box Message Label var dataTable = Charts.newDataTable() .addColumn(Charts.ColumnType.STRING, "Quarter") .addColumn(Charts.ColumnType.NUMBER, "Income") .addColumn(Charts.ColumnType.NUMBER, "Expenses") .addRow(["Q1", 50, 60]) .addRow(["Q2", 60, 55]) .addRow(["Q3", 70, 60]) .addRow(["Q4", 100, 50]) .build(); return dataTable; }
  • 20. Charts Services - 2/2 function buildChart(dataTable) { // Build the chart. We'll make income green and expenses red var chart = Charts.newColumnChart() .setDataTable(dataTable) .setColors(["green", "red"]) .setDimensions(600, 400) .setXAxisTitle("Quarters") .setYAxisTitle("$") .setTitle("Income and Expenses per Quarter") .build(); return chart; } function main() { var chart = buildChart(getData()); var ui = UiApp.createApplication(); ui.add(chart); SpreadsheetApp.getActiveSpreadsheet().show(ui); }
  • 21. Triggers ● Trigger ~= Event handler ● Triggers allow asynchronous execution of scripts ○ Helps in automation ○ A user no longer has to manually execute the script ● Two Types of Triggers ○ Event Driven - onEdit, onInstall, onOpen ○ Time Driven
  • 22. Resources ● Apps Script documentation ○ http://code.google.com/googleapps/appsscript/ ● Tutorials ○ http://code.google.com/googleapps/appsscript/articles.html ● Online community ○ http://www.google.com/support/forum/p/apps-script/ ● Google Apps Script Blog ○ http://googleappsscript.blogspot.com/