💻
Code Snippet
  • Overview
  • General
    • Anaconda
  • GUI
    • PyQT
      • Qt Design
  • Pandas
    • Read Data
    • Replace
  • Articles
    • Python. PyQt
    • Offline Payment Wallet With Django
    • Documentation Encrypt File
    • Play With Pillow
  • Fontend
    • Snippet
    • Hugo
    • JavaScript
      • Form Validation
  • Finance
    • Library
      • yfinance
  • Notebook
    • Untitled
    • Snippet
  • Python
    • Download file
    • Date and Time
    • Snippet
    • Compile .exe
    • Overview
    • Google
      • Samples for Google Workspace
      • Drive
      • GoogleSheet
    • Virtual environment
    • Database
      • Pickle()
    • Datatypes
      • Excel
      • Dictionary
        • xmltodict()
    • File Handling
      • shutil()
      • Get the File Name
      • Get the Full Path
      • Check the File Size
      • Get File Creation Date
      • Find All File
        • Untitled
    • Dictionary
      • Convert Two Lists
  • Data Science
    • HTTP requests
  • Google Workspace
    • Overview
    • Apps Script
      • ์Note
      • Overview
      • Snippet
        • HTML Service
        • Fetch API
      • Quickstart
      • Google Sheets
        • Overview
          • Snippet
        • Fundamentals
          • Macros & Custom Functions
          • Spreadsheets, Sheets, and Ranges
          • Working with Data
          • Data Formatting
          • Chart and Present Data
        • Built-in Google Services
        • Fetch and format API data
        • Connected Sheets
  • Git
  • Mini Lab
    • Line
    • Python
  • Function
    • Python
      • Date&Time
  • Database
    • SQLite
      • Example
Powered by GitBook
On this page
  • Built-in Google Services
  • Modern JavaScript features
  • Using autocomplete
  • Understanding global objects
  • Calling methods
  • Accessing child classes
  • Dealing with interfaces
  • Working with enums

Was this helpful?

  1. Google Workspace
  2. Apps Script
  3. Google Sheets

Built-in Google Services

PreviousChart and Present DataNextFetch and format API data

Last updated 3 years ago

Was this helpful?

Built-in Google Services

Google Apps Script provides more than 30 built-in services for interacting with user data, other Google systems, and external systems. These services are provided as global objects akin to JavaScript's standard object. For example, just as Math offers methods like random() and constants like PI, Apps Script's offers methods like , classes (child objects) like , and enums like .

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

Modern JavaScript features

Apps Script supports two JavaScript runtimes: the modern runtime and an older one powered by Mozilla's .

The supports modern syntax and features. The Rhino runtime is based on the older standard, plus a few features from and . You can to use with your script, but the V8 runtime is strongly recommended.

Each runtime supports JavaScript classes and objects that are available to your script in addition to the built-in and . Your scripts can use common objects like , , , , as well as the and global objects.Note: Because Apps Script code runs on Google's servers (with the exception of pages), browser-based JavaScript features like DOM manipulation or the API are not available 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 enums that are valid in the script's current context. Autocomplete suggestions appear automatically whenever you type a period after a global object, enum, or method call 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 valid suggestions that begin with those characters.

Understanding global objects

Each service provides at least one global (top-level) object; for example, the is accessed solely from the object. Some services provide multiple global objects; for example, the includes four global objects: , , , and .

Calling methods

GlobalObjectName.methodName(argument1, argument2, ..., argumentN);
GmailApp.sendEmail('claire@example.com', 'Subject line', 'This is the body.');
var doc = DocumentApp.create('New document');
var body = doc.getBody();
body.appendParagraph('New paragraph.');

// Same result as above.
DocumentApp.create('New document').getBody().appendParagraph('New paragraph.');

Accessing child classes

Dealing with interfaces

Working with enums

// Creates a folder that anyone on the Internet can read from and write to. (Domain administrators can
// prohibit this setting for Google Workspace users.)
var folder = DriveApp.createFolder('Shared Folder');
folder.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.EDIT);

Reference : https://developers.google.com/apps-script/guides/services

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

For example, a script can send an email by calling the method of the Gmail service like so:

If a method returns another Apps Script class, you can chain method calls on one line. (Return types are shown both in autocomplete and in a method's reference documentation.) For example, the method returns a ; thus, the following two sections of code are equivalent:

Every service includes one or more child classes that cannot be accessed from the top level as a global object can. You cannot use the new keyword to construct these classes, as you can with standard JavaScript classes like ; you can only access a child class by calling a method that returns it. If you're not sure how to access a certain class, visit the root page for the service's reference documentation and look for a method that returns the class you want.

A handful of services include special classes that are labeled as "interfaces" in the reference documentation. These are generic classes used as return types for methods that cannot determine the precise type in advance; for example, the method returns a generic object. Element is an interface that represents some other class, possibly a or . Interface objects are rarely useful on their own; instead, you usually want to call a method like to cast the object back to a precise class.

Most services include a few enums (enumerated types) of named values. For example, the uses the enums and to determine which users have access to a file or folder. In almost all cases, you access these enums from the global object. For example, a call to the method looks like this:

Math
Spreadsheet service
openById(id)
Range
DataValidationCriteria
V8
Rhino JavaScript interpreter
V8 runtime
ECMAScript
JavaScript 1.6
1.7
1.8
freely choose which runtime
advanced Google services
Array
Date
RegExp
and so forth
Math
Object
HTML-service
Window
Gmail service
GmailApp
Base service
Browser
Logger
MimeType
Session
advanced services
sendEmail(recipient, subject, body)
DocumentApp.create()
Document
Date
Document service
Body.getChild(childIndex)
Element
Paragraph
Table
Element.asParagraph()
Drive service
Access
Permission
Folder.setSharing(accessType, permissionType)