O'Reilly logo

Google Script: Enterprise Application Essentials by James Ferreira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required



If you are reading this book, there is a good chance you have heard of Google and its powerful office productivity suite, Google Apps. Google offers search, email, word processing, and hundreds of other cloud applications and services that can be available to the individual and can scale all the way up to massive corporations and governments. As one of Google’s most popular services, Google Apps offers some of the best online office products available and is an excellent example of web-based applications that out perform legacy desktop software.

This book is about Google Apps Script, which is a service that runs from Google Apps, like Sites and Documents. Google Script is extremely powerful when automating many of the tasks required by day-to-day spreadsheet operations, but it also scales up to provide a complete application platform. If you are coming from a Microsoft Office direction, you can think of it as the macros for Google Documents, but unlike simple macros in MS Office, Google Script has a mature online editor with all the features one would expect in a development platform. Unleash Google Script’s user interface capability and you can create entire data driven websites and applications that run across most modern browsers, including mobile.

In addition to the integrated development environment (IDE), Google Script comes complete with a manager for organizing scripts, built-in debugging, auto code completion, timed event triggers, and automated revisioning to name a few features. What really caught this author’s attention was that everything is web-based. There is no need to download and configure a code editor or transport development files from computer to computer, wasting time resynchronizing files and reconnecting libraries. Simply sign into your Google account and start creating. Google Scripts are written in the JavaScript language version 1.8/ECMA 262 (3rd Edition), so there is no need to compile the code, making application development very fast.

With its own set of libraries, Google Script can interact with most of the services provided by Google, making it the Swiss army knife behind the mainline products. Other application building methods for accessing Google products like App Engine and the gData APIs, offered in many different languages, all require a place for you to develop and deploy your code. With Google Script, you are building the code into the existing Google platform, and that equates a robust experience where your products are inherent in Google’s legendary 99.9 percent availability. Because there is no need to have anything more than a basic Internet connected browser, development on this platform is something anyone can get started with, and there is no upfront expense. Google Script is not locked inside Google where it can only talk to Google servers, rather it can communicate through JDBC, JSON, SOAP, and has a urlFetch method making it very versatile when communicating across the Web.

At Google I/O 2010, a new feature called UiApp was unveiled, giving Google Script programmers the ability to build custom user interfaces that can run inside a spreadsheet window as a Google Gadget or completely independent in a browser. Talk about earth shattering, a cloud programing platform that can access just about any web-based service and has the ability to create AJAX style web pages? That is noteworthy. One year later, in 2011, additional improvements were added, giving Google Script a drag-and-drop visual editor. This feature reduces the amount of code writing and makes creating an application more approachable for power users with limited coding experience. To date, Google Script is the only way to gain full access to Gmail at the message level.

This book will focus on teaching you how to build powerful web applications using Google Script. It is laid out in sections that explain how the different parts of Google Script work and puts all these together in a series of fully functional applications that you can put to work right away.

Who Should Read This Book

This book is perfect for anyone who wants to extend what can be done with Google Apps but is not ready to dive into the complicated world of the Google Web Tool Kit and Java APIs. You don’t have to be a webmaster or programmer to grasp the concepts in this book. Google Script takes care of server configuration, gives you a place to save your projects and allows you to start developing immediately. This book is approachable by anyone with basic coding skills and a fundamental understanding of JavaScript. If you have never used JavaScript, I recommend having a copy of Head First JavaScript (O’Reilly) close at hand to help you through concepts like variables, arrays, and objects. All the application examples have highly detailed explanations, so if you are a Google Apps power user, you should not have difficulty grasping the content in this book and writing incredible applications using Google Script.

What You Will Need

You will need a web browser (I recommend Chrome) and any type of Google account. That’s it! Google Script is a completely web-based solution that is free and ready for you to start programming today.

Conventions Used in This Book

The following typographical conventions are used in this book:


Indicates new terms, URLs, email addresses, filenames, and file extensions.

Constant width

Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context.


This icon signifies a tip, suggestion, or general note.


This icon indicates a warning or caution.

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Google Script: Enterprise Application Essentials by James Ferreira (O’Reilly). Copyright 2012 James Ferreira, 978-1-449-31852-9.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

Safari® Books Online


Safari Books Online is an on-demand digital library that lets you easily search over 7,500 technology and creative reference books and videos to find the answers you need quickly.

With a subscription, you can read any page and watch any video from our library online. Read books on your cell phone and mobile devices. Access new titles before they are available for print, and get exclusive access to manuscripts in development and post feedback for the authors. Copy and paste code samples, organize your favorites, download chapters, bookmark key sections, create notes, print out pages, and benefit from tons of other time-saving features.

O’Reilly Media has uploaded this book to the Safari Books Online service. To have full digital access to this book and others on similar topics from O’Reilly and other publishers, sign up for free at http://my.safaribooksonline.com.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:


To comment or ask technical questions about this book, send email to:

For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.

Find us on Facebook: http://facebook.com/oreilly

Follow us on Twitter: http://twitter.com/oreillymedia

Watch us on YouTube: http://www.youtube.com/oreillymedia

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required