Google Apps Script
Encyclopedia
Google Apps Script is a cloud based scripting language for light-weight application development in the Google Apps platform. It is based on JavaScript, however instead of running on the client, it gets executed in the Google Cloud. Google Apps Script essentially provides easy ways to automate tasks across Google products and third party services.

Benefits

  1. Based on JavaScript-like syntax. Easy to learn.
  2. Under the hood, Google Apps Script uses the Google Web Toolkit
    Google Web Toolkit
    Google Web Toolkit is an open source set of tools that allows web developers to create and maintain complex JavaScript front-end applications in Java. Other than a few native libraries, everything is Java source that can be built on any supported platform with the included GWT Ant build files...

     (GWT) to create and display user interface elements. GWT is easy to learn, and completely abstracts the complexity of AJAX/HTML from the developer.
  3. Cloud based debugger for debugging App Scripts in the web browser.

Limitations

  1. Currently Google Apps Script does not allow connection to internal (behind-the-firewall) corporate databases, which is key to building business apps. Similarly, lack of other connectivity, such as LDAP connectivity, limits the level to which GAS can be used in the enterprise.
  2. There is no way to share scripts i.e. a new instance has be created for each use. This creates overhead when it is time to update a script, since each instance has to be update manually.
  3. UI Widgets in Google Apps Script lack support for displaying HTML
    HTML
    HyperText Markup Language is the predominant markup language for web pages. HTML elements are the basic building-blocks of webpages....

     formatted content. This severely limits the formatting of text displayed in a Google Apps Script app.

Example

The following code demonstrate use of Google Apps Script UI Services and DocList Services to display contents of a Google Docs Collection in Tree format.

Notice the use of JavaScript
JavaScript
JavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....

-like syntax and the use of Google Web Toolkit
Google Web Toolkit
Google Web Toolkit is an open source set of tools that allows web developers to create and maintain complex JavaScript front-end applications in Java. Other than a few native libraries, everything is Java source that can be built on any supported platform with the included GWT Ant build files...

widgets.



function doGet(e){
var app = UiApp.createApplication;
var scrollPanel = app.createScrollPanel; // Scroll Panel is a Google Web Toolkit Widget
tree = app.createTree; // Tree is a Google Web Toolkit Widget
tree.addItem(buildTree(app, "Enterprise 2.0 - Saqib"));
scrollPanel.add(tree);
scrollPanel.setHeight("500");
app.add(scrollPanel);
return app;
}

function buildTree(a, searchTerm){
var tree = a.createTreeItem; // TreeItem is Google Web Toolkit Widget
tree.setText(searchTerm);

// Use of the Google Apps Script DocList Service to retrieve the collections.
var folders = DocsList.getFolder(searchTerm).getFolders;
for (var i = 0; i < folders.length; i++)
tree.addItem(buildTree(a, folders[i].getName)).setState(true, true);

var files = DocsList.getFolder(searchTerm).getFiles;
for (var i = 0; i < files.length; i++) {
if (files[i].getType

"document") {
urlBase = "https://docs.google.com/document/edit?id=";
iconHTML = "https://docs.google.com/images/doclist/icon_7_document_list.png";
}
else if (files[i].getType

"spreadsheet") {
urlBase = "https://spreadsheets.google.com/ccc?key=";
iconHTML = "https://docs.google.com/images/doclist/icon_7_spreadsheet_list.png";
}
else if (files[i].getType

"presentation") {
urlBase = "https://docs.google.com/present/edit?id=";
iconHTML = "https://docs.google.com/images/doclist/icon_7_presentation_list.png";
}
else if (files[i].getType

"drawing") {
urlBase = "https://docs.google.com/drawings/edit?id=";
iconHTML = "https://docs.google.com/images/doclist/icon_7_drawing_list.png";
}
else {
urlBase = "https://docs.google.com/fileview?id=";
iconHTML = "https://docs.google.com/images/doclist/icon_7_generic_list.png";
}

var image = a.createImage(iconHTML);
var fileLabel = a.createAnchor(files[i].getName, urlBase+ files[i].getId);
var fileLabelPanel = a.createHorizontalPanel;
fileLabelPanel.add(image);
fileLabelPanel.add(fileLabel);
tree.addItem(fileLabelPanel).setState(true, true);
}
return tree;
}
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK