Google Apps Script

Overview

Google Web Scripts gives users a new level of control over Google products. Now you can access and control Google Spreadsheets and other products via JavaScript scripts you can write yourself and share with others. Unlike browser-based JavaScript, the scripts you write run directly on Google servers in order to provide direct access to the products they control.

The Scripts API is a set of classes and methods available to all your functions. The richest API currently available is for Google Spreadsheets, but there are also basic versions for Google Calendar and GMail. Check the details of our APIs reference.

Contents

Server-Side JavaScript

Traditionally, JavaScript is a client-side scripting language that has enabled modern web browsers to run fully fledged online applications.

By running our own JavaScript interpreters on the server-side, we provide an efficient way for your Scripts to interact with Google products. Typically, a user triggers the server-side execution of a Script from a Google product and is able to visualize the results in real time as the Script is executed on the Google Cloud.

Since your Google Apps Scripts are stored and executed on the server side, you can share them just as you do your spreadsheets, documents, and other data created on Google products. But exercise caution when running scripts that have been shared with you. Scripts may require access to your private data in order to run. The first time you run a script, an authorization panel will show you what Products the script is going to interact with on your behalf and ask you to grant or deny access. Consider how well you trust the source of the script, and how private the data you're granting access may be. Untrustworthy scripts may use your private data for other purposes than what the script itself claims to do. You always have the option to inspect the any script code before granting access.

The Script Editor: Creating And Running Scripts

The Script Editor is available from the Tools menu in Google Spreadsheets. On the left side, it shows a list of scripts associated with a given spreadsheet. The purpose of the Script Editor is to provide a basic online development environment to create, collaborate, store and run scripts.

Scripts consist of JavaScript variables, functions and classes. Any function can be invoked directly from the Script Editor, except those with a name that ends with an underscore, which can only be called from other functions. Functions will not be able to change any state in the execution environment, although you can simulate that behavior by modifying spreadsheets cells.

Functions will also be unable to reference functions defined in a different script. Any function you intend to call within another function, must be defined in the same script.

Different ways of invoking Scripts

You can invoke scripts in different ways:

  • by referencing it from a Spreadsheet cell formula as if it was a existing Spreadsheet function, for instance =myCustomFunction(A1)
  • . These custom functions may only modify the value of the local cell. Any use of API methods that interact with Google products will result in an error.
  • by clicking on the Run button from the online Script Editor
  • from a custom menu in a Spreadsheet
  • by clicking on a drawing embedded in a Spreadsheet