Built-in Google Services

  • Google Apps Script offers over 30 built-in services for interacting with user data, other Google systems, and external systems, provided as global objects.

  • Google Apps Script supports both the modern V8 and older Rhino JavaScript runtimes, with the V8 runtime being strongly recommended for its support of modern ECMAScript features.

  • The script editor provides an autocomplete feature that assists in identifying valid global objects, methods, and enums within the script's current context.

  • Services are accessed through global objects, and methods can be called on these objects to perform actions or retrieve data, with the ability to chain method calls when they return other Apps Script classes.

  • Child classes cannot be accessed directly but must be accessed by calling a method that returns an instance of that class, and some services use "interface" classes to represent generic types that can be cast to a precise class.

Google Apps Script provides more than 30 built-in services for interacting withuser data, other Google systems, and external systems. These services areprovided as global objects akin to JavaScript's standardMathobject. For example, just asMath offers methods likerandom() andconstants likePI, Apps Script'sSpreadsheet service offers methods likeopenById(id),classes (child objects) likeRange, and enums likeDataValidationCriteria.

The reference documentation for services that controlGoogle Workspace products are collected in the"Google Workspace Services" section under the"Reference" header in the sidebar of this site. Utility services (for thingslike creating user interfaces, parsing XML, or writing log data) are collectedin the "Script Services" section.

Modern JavaScript features

Apps Script supports two JavaScript runtimes: the modernV8 runtime and an older one powered by Mozilla'sRhino JavaScript interpreter.

TheV8 runtime supports modernECMAScript syntax and features.The Rhino runtime is based on the olderJavaScript 1.6standard, plus a few features from1.7 and1.8.You canfreely choose which runtimeto use with your script, but the V8 runtime is strongly recommended.

Each runtime supports JavaScript classes and objects that are available to yourscript in addition to the built-inandadvanced Google services. Yourscripts can use common objects likeArray,Date,RegExp,and so forth,as well as theMath andObjectglobal objects.

Note: Because Apps Script code runs on Google's servers (with theexception ofHTML-service pages),browser-based JavaScript features like DOM manipulation or theWindow API are notavailable in Apps Script.

Using autocomplete

The script editor provides a "content assist" feature, more commonly called"autocomplete," which reveals the global objects as well as methods and enumsthat are valid in the script's current context. Autocomplete suggestions appearautomatically whenever you type a period after a global object, enum, or methodcall that returns an Apps Script class. For example:

  • If you type the full name of a global object or select one from autocomplete,then type. (a period), you will see all methods and enums for that class.
  • If you type a few characters, you'll see all validsuggestions that begin with those characters.

Understanding global objects

Each service provides at least one global (top-level) object; for example,theGmail service is accessed solely fromtheGmailApp object. Some servicesprovide multiple global objects; for example, theBase service includes four global objects:Browser,Logger,MimeType, andSession.

Calling methods

The global objects of nearly all built-in oradvanced services include methods thatreturn data or an Apps Script class. Scripts make method calls in this format:

GlobalObjectName.methodName(argument1, argument2, ..., argumentN);

For example, a script can send an email by calling thesendEmail(recipient, subject, body)method of the Gmail service like so:

GmailApp.sendEmail('claire@example.com','Subject line','This is the body.');

If a method returns another Apps Script class, you can chain method calls on oneline. (Return types are shown both in autocomplete and in a method's referencedocumentation.) For example, the methodDocumentApp.create()returns aDocument; thus, thefollowing two sections of code are equivalent:

vardoc=DocumentApp.create('New document');varbody=doc.getTab('t.0').asDocumentTab().getBody();body.appendParagraph('New paragraph.');//Sameresultasabove.DocumentApp.create('New document').getTab('t.0').asDocumentTab().getBody().appendParagraph('New paragraph.');

Accessing child classes

Every service includes one or more child classes that cannot be accessed fromthe top level as a global object can. You cannot use thenew keyword toconstruct these classes, as you can with standard JavaScript classes likeDate;you can only access a child class by calling a method that returns it. If you'renot sure how to access a certain class, visit the root page for the service'sreference documentation and look for a method that returns the class you want.

Dealing with interfaces

A handful of services include special classes that are labeled as "interfaces"in the reference documentation. These are generic classes used as return typesfor methods that cannot determine the precise type in advance; for example,theDocument service methodBody.getChild(childIndex)returns a genericElement object.Element is an interface that represents some other class, possibly aParagraph orTable. Interface objects are rarelyuseful on their own; instead, you usually want to call a method likeElement.asParagraph()to cast the object back to a precise class.

Working with enums

Most services include a few enums (enumerated types) of named values. Forexample, theDrive service uses the enumsAccess andPermission to determine which usershave access to a file or folder. In almost all cases, you access these enumsfrom the global object. For example, a call to the methodFolder.setSharing(accessType, permissionType)looks like this:

//CreatesafolderthatanyoneontheInternetcanreadfromandwriteto.(Domainadministratorscan//prohibitthissettingforGoogleWorkspaceusers.)varfolder=DriveApp.createFolder('Shared Folder');folder.setSharing(DriveApp.Access.ANYONE,DriveApp.Permission.EDIT);

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.