Google Apps Script

Apps Script is a scripting platform developed by Google for light-weight application development in the Google Workspace platform. Google Apps Script was initially developed by Mike Harm as a side project whilst working as a developer on Google Sheets.[2] Google Apps Script was first publicly announced in May 2009 when a beta testing program was announced by Jonathan Rochelle, then Product Manager, Google Docs.[3] In August 2009 Google Apps Script was subsequently made available to all Google Apps Premier and Education Edition customers.[4] It is based on JavaScript 1.6, but also includes some portions of 1.7 and 1.8 and a subset of the ECMAScript 5 API.[5] Apps Script projects run server-side on Google's infrastructure. According to Google, Apps Script "provides easy ways to automate tasks across Google products and third party services."[6] Apps Script is also the tool that powers the add-ons for Google Docs, Sheets and Slides.[7]

Apps Script
Developer(s)Google
Initial releaseAugust 19, 2009 (2009-08-19)[1]
Written inJavaScript
TypeWeb application framework, scripting framework
Websitescript.google.com

Benefits

  1. Based on JavaScript 1.6 and a selection of JavaScript 1.7 and 1.8[8]
  2. Cloud based debugger for debugging App Scripts in the web browser.
  3. It can be used to create simple tools for an organization's internal consumption.
  4. It can be used to perform simple system administration tasks.
  5. Community-based support model.

Limitations

  1. Processing limitations  As a cloud-based service, Apps Script limits the time that a user's script may run, as well as limiting access to Google services.[9]
  2. Currently Google Apps Store does not allow direct connection to internal (behind-the-firewall) corporate databases, which is key to building business apps, however, via use of the JDBC service, this can be overcome, if connections are allowed from Google servers to the internal database server.[10] Similarly, lack of other connectivity, such as LDAP connectivity, limits the level to which GAS can be used in the enterprise.
  3. Due to the cloud nature of Apps Script, functions related to date and time will produce results that seem to be incorrect due to the data crossing time zones. Using Date/Time objects and functions without very precise declaration and thorough testing may result in inaccurate results.[11]

Example

function doGet(e) {  
  var searchTerm = 'Script Tools'
  var ui = XmlService.createDocument(XmlService.createElement('html')).setDocType(XmlService.createDocType('html'))
  var body = XmlService.createElement('body')  
  body = buildTree(body, searchTerm);
  ui.getRootElement().addContent(body)
  return HtmlService.createHtmlOutput(XmlService.getRawFormat().format(ui))
}


function buildTree(node, searchTerm) {
  var ul = XmlService.createElement('ul').addContent(XmlService.createElement('p').addContent(XmlService.createText(searchTerm))); 
  // Use of the Apps Script DriveApp Service to retrieve the collections.  
  var folders = DriveApp.getFoldersByName(searchTerm).next().getFolders()
  while (folders.hasNext()){    
    var thisFolder = folders.next();   
    var li = XmlService.createElement('li');   
    var resp = buildTree(li, thisFolder.getName())            
    ul.addContent(li);
  }

  var files =  DriveApp.getFoldersByName(searchTerm).next().getFiles()   
  while (files.hasNext()) {    
    var thisFile = files.next()    
    if (thisFile.getMimeType() === "application/vnd.google-apps.document") {
      urlBase = "https://docs.google.com/document/edit?id=";
      iconHTML = "https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.google-apps.document";
    }    
    else if (thisFile.getMimeType() === "application/vnd.google-apps.spreadsheet") {      
      urlBase = "https://spreadsheets.google.com/ccc?key=";
      iconHTML = "https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.google-apps.spreadsheet";
    }
    else if (thisFile.getMimeType() === "application/vnd.google-apps.script") {      
      urlBase = "https://docs.google.com/fileview?id=";
      iconHTML = "https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.google-apps.script";
    }
    else if (thisFile.getMimeType() === "application/vnd.google-apps.presentation") {       
      urlBase = "https://docs.google.com/present/edit?id=";
      iconHTML = "https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.google-apps.presentation";
    }
    else if (thisFile.getMimeType() === "application/vnd.google-apps.drawing") {       
      urlBase = "https://docs.google.com/drawings/edit?id=";
      iconHTML = "https://drive-thirdparty.googleusercontent.com/32/type/application/vnd.google-apps.drawing";       
    }
    else {
      urlBase = "https://docs.google.com/fileview?id=";
      iconHTML = "https://drive-thirdparty.googleusercontent.com/32/type/application/application/vnd.google-apps.unknown";    
    }    
    
    var li = XmlService.createElement('li');     
    var image = XmlService.createElement('img').setAttribute('src', iconHTML);    
    var fileLabel =  XmlService.createElement('a').setAttribute('href', urlBase + thisFile.getId())
                      .setAttribute('target', '_blank').addContent(XmlService.createText(thisFile.getName()))
    var fileLabelPanel = XmlService.createElement('div').setAttribute('style', 'display:flex;flex-direction: row;')
    fileLabelPanel.addContent(image)
    fileLabelPanel.addContent(fileLabel)    
    li.addContent(fileLabelPanel)
    ul.addContent(li)
  }    
  node.addContent(ul)
  return node;   
}

Add-ons

In March 2014, Google introduced add-ons for Docs and Sheets (soon followed by Forms). The add-on stores let users add extra features to Google editors, such as mail-merging, workflows, diagrams builders,... All add-ons are either 100% built with Apps Script or simply use Apps Script to display a UI in the Google editors while relying on an external backend to perform some tasks. For example, MailChimp, a mail-merging tool, has an add-on for Google Docs that communicates with MailChimp platform to send emails.

Before add-ons, it was possible to publish scripts for Google Sheets in the Script Gallery. When users installed scripts through this gallery, a copy of the Apps Script code was installed on the user's Sheet. With add-ons, the source code is not visible to the end user and everyone is using the latest version published by the developer. This new approach make it easier to support existing code and helped convince several companies, such as MailChimp or LucidChart to invest in Apps Script.

As part of the add-ons release, Google also introduced a UI Style Guide[12] and CSS package to help developers built add-ons that integrate smoothly into the editors. Each add-on is also reviewed by Google before its publication and developers can benefit from advice from Googlers to provide a better user experience. It is not possible to embed ads in add-ons but it is possible to monetize them.[13]

See also

References

  1. Meyer, David (August 20, 2009). "Google Apps Script gets green light". CNet. Retrieved 26 March 2011.
  2. Koleda, Eric (August 21, 2019). "Celebrating 10 years of Apps Script: looking back on how it started". Google Cloud Blog. Retrieved 22 August 2019.
  3. Rochelle, Jonathan (May 27, 2009). "Old tool, new tricks". Google Cloud Blog. Retrieved 22 August 2019.
  4. Levey, Evin (August 19, 2009). "Google Apps Script Launched to Google Apps Premier and Education". Google Apps Script. Retrieved 22 August 2019.
  5. Kienle, Holger (May–June 2010). "It's About Time to Take JavaScript (More) Seriously". IEEE Software. 27 (3): 60–62. doi:10.1109/MS.2010.76. Archived from the original on 29 June 2010. Retrieved 25 March 2011.
  6. Google Apps Script
  7. Bring a little something extra to Docs and Sheets with add-ons
  8. Google Inc. (August 28, 2018). "Built-in Google Services". Google Apps Script. Retrieved 16 May 2019.
  9. https://developers.google.com/apps-script/guides/services/quotas
  10. https://developers.google.com/apps-script/guides/jdbc
  11. "Issue 1035: utilities.formatdate subtracts a day". Retrieved 17 December 2012.
  12. UI Style Guide for Add-ons
  13. I've started a little experiment...
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.