ASS04: Understanding Script Editor Features

Google Apps Script editor is a powerful, built-in development environment within Google Workspace. It allows you to create and customize scripts using JavaScript to automate tasks and extend the functionality of Google applications like Google Sheets, Docs, Slides, and Forms.

The Script Editor can be intimidating for beginners. This tutorial offers a guide to navigating the editor, understanding its interface, and setting up your first script. You'll learn the fundamental elements of the editor in an engaging and easy-to-follow format, making it approachable for new users.

Header & Sidebar

The project name can be changed by clicking on it in the header. The blue deploy button is an advanced feature that will be explained later in this tutorial.

The sidebar, located within the editor, contains six pages: Overview, Editor, Project History, Triggers, Executions, and Project Settings.

Overview

In this page, you will find the Apps Script Project Details, Deployments, and Project OAuth Scopes.

The Project details section contains fundamental information about the Apps Script project, including the container, owner, role, status, last run, created, and last modified dates. If you have the necessary permissions, you also have the option to make a copy, star, or delete the project.

The deployments section displays key details about project deployments, including error rates, executions, users, and an overall health report. Typically, you'll find three deployments listed here, assuming you've deployed the project. The HEAD deployment represents the deployment using the most recent project code, while the "Initial Deployment" refers to the latest production deployment. Note that the name of the "Initial Deployment" can vary, as it's determined by you during the deployment process.

The project OAuth scopes are typically automatically assigned by Google based on the Google APIs used in the project. However, they can also be manually managed in the appsscript.json file. For further information, please refer to this document provided by Google.

Editor

The left side of the editor contains the file, library, and advanced service managers. Files can be added, sorted, renamed, copied, deleted, and moved within the file manager. Please note that Apps Script currently supports mainly script (.gs) and HTML (.html) files; the appsscript.json file is the project's manifest file. In the libraries section, you can add your own libraries or libraries from others. The services section contains advanced Google API services, such as Sheets API, Drive API, People API, and YouTube API. These are not enabled by default and must be added and enabled before use in a project.

Now, let's take a look at the editor itself. At the top, you'll find the action menu, where you can perform tasks like undo, redo, save changes, run or debug the selected function, and access the execution log of the last script that was run. The main interface for entering your script is located below the menu, and line numbers are automatically assigned as you type.  Clicking before a line number allows you to set a breakpoint for debugging; you can set multiple breakpoints, and the script will stop at each one. Finally, right-clicking on the editor will reveal a "more actions" menu. The most frequently used actions here are "Go to Definition", "Go to References", and "Format Document".

Project History

“A version is a static copy of a script. Versions let you track your changes. Once you save a version, you can't modify it. Use versions when you're working on a script that goes through many changes and iterations. Script projects can have up to 200 versions.” - from Google

The changes will be reflected in the project. Choose a version to view, delete, or compare it with another version by toggling the "Highlight changes" option.

Triggers

The triggers section is an essential part of Apps Script projects, as it often initiates automation. Within this section, you can manually create, edit, or delete triggers (if you own them). You can also view all triggers created by you and your collaborators, along with an overview of their statuses.

This is only a brief overview of triggers; we will go into more detail in later tutorials. You can always refer back to this document for more information.

Executions

The executions section displays a log of all current and past executions for the project. Developers can use this section to select an execution and review its logs.

For further information, please consult this Google resource.

Project Settings

The general settings allow you to change the timezone and configure the project. I recommend selecting all the project configuration options. You can also find and copy the script project ID in the general settings. Additionally, the project ID is located in the project URL.

If your project requires the use of ES5, an older version of JavaScript, you can enable it by unchecking the Chrome V8 runtime (ES6) environment.

If you need to connect your own GCP project to your Apps Script project for any reason, you can do that here. Otherwise, a default GCP project will be assigned automatically to each Apps Script project. For instructions on how to do this, please refer to this Google document.

A Complete Guide to Setup GCP for GAS

Script properties offer a streamlined storage solution for data that will be used within your script. This lightweight option is commonly used for storing sensitive information such as passwords and API keys. However, it's important to note that script properties do have limitations. For further details, refer to this Google document.

Apps Script Simplified

Links

Join Memberships Make a copy Github Hire Me Buy Me a Coffee

Previous Read

ASS03: Creating Your First Apps Script Project

Next Read

ASS05: Introduction to the Google Sheets API

Comments