everything you need to know to get started » 【2022】

If you use Google services such as Google Docs, Google Sheets, Google Analytics, Gmail, and others, you can connect and automate these services using Google Apps Script.

Think of Google Apps Script as Google’s version of Microsoft’s VBA script. Just as you can automate actions and tasks or customize macros in Microsoft Word and Excel with VBA, you can automate tasks and actions in Google services. In services like Sheets and Docs, you can even write your own custom menus.

In this article, you’ll learn how to access and enable Apps Script in your various Google services, how to navigate Apps Script Editor, and how to connect services. You won’t learn specific scripting functions, but Google has great app scripting documentation and tutorials for learning how to write app scripts.

How to Access the Google Apps Script Editor

You can open the Google Apps Script code editor from various Google services. For example, you will find application scenario in the Extensions menu in Google Sheets.

In other services, you can open the Google Apps Script editor in the following ways:

  • Google Docs: Select script editor in the Instruments menu.
  • google slides: Select script editor in the Instruments menu.
  • google forms: Select script editor in the three-dot menu.
  • Google Drive: Right click on any empty space, select Moreand select Scripting Google Apps.

Either method opens the Apps Script code editor in a new tab. This is the window where you will write each of the functions that make up your entire script. By default, you will see an empty function called myFunction() which is ready for you to start completing your code.

To note: The format of the code is very important to avoid errors. Use comments as shown in the following code to remind you of what you were trying to do in the code sections. This is very similar to how comments in HTML code work with web programming.

While browsing the code editor, you can return to this section by selecting Code.gs in the left navigation pane in the Editor the window. To see the other available windows, hover over the icons in the left panel and the main navigation panel will open.

the General description The section is where you can find statistics about your script, such as the number of errors it encountered, the number of times it ran, etc.

We’ll cover each of the other sections of the Google Apps Script editor in each section below.

Navigating the Google Apps Script Editor

When editing your code in the editor, it’s a good idea to frequently select the disk (Save) icon so you don’t lose your work.

Once saved, you will see the other menu options light up.

These include:

  • Run: try to run the entire script from start to finish.
  • Debug: Advance through your script one line at a time.
  • Features drop-down menu: browse and access each of the functions you have created.
  • Execution log: View status or error messages for each attempt to run your script.

the libraries The option in the left navigation menu allows you to access libraries that other people have written (or that you have written and saved elsewhere). This is useful if you have a friend who has already written a function that you would like to use in Google Sheets or Google Docs, but would like to add additional functions on top of it.

All you need to add these libraries to your project is the script ID. You can find it in the project settings section, which we’ll show you how to find towards the end of this article.

Google Apps Scripting Services Plugins

the Services The section is the most useful. This is where you can integrate your current script with other Google services you may use.

When you select it, you will see the Add a department open window Scroll to the service you want to use to complement your existing project.

For example, if you want to pull data from your Google Analytics account in this script, you can select the option Google Analytics APIsand select Add.

If you want to find details about the features available for this new add-on service and how to use them, select the three dots to the right of the API and select See documentation.

This will open the Google Apps Script documentation in a new tab, which will automatically open to that Google service section.

Browse the documentation for function syntax, tutorials, and sample code you can use in your own script.

Also note that you can navigate to other sections of the documentation to see what general features are available in your script depending on the service you were using when you opened the Apps Script code editor.

For example, if you opened the editor in Google Sheets, check the box Sheets section in the documentation menu for Google Sheets functions you can use in your script.

Configuring and Using Application Script Triggers

Another useful feature of Google Apps Script is the ability to set triggers based on a series of events or times.

To configure a new trigger for your script, select triggers in the navigation menu on the far left. In the new Triggers window that opens, select the add a trigger button.

The Add Trigger window contains a long list of options that help you customize exactly how and when you want your script to run.

To note: Many of these options depend on the service you are writing your script for or the APIs you have added.

To configure your trigger, you will need to choose:

  • Which function to start initially
  • The source of the event, such as a specific date or time, or an event in your service, such as a change in a Google Spreadsheet cell or the first opening of a document.
  • The type of event, such as when an item is opened or changed in your doc or Google spreadsheet, or specific date or time settings.
  • Notification frequency on how often you want to receive updates when your scripts have failed

Once you have selected SaveYou may see the message “Script authorization failed” if this is your first time registering a new trigger.

This is usually triggered if you have enabled a pop-up blocker in your browser. If you’re using Google Chrome, just select the little window icon with a red “X” on it. Change the setting to Always allow pop-ups and select Made.

when you select Save again, you will need to go through the process to allow the script you wrote to run on your Google account or Google Workspace.

First, select the Google Account where you want to allow your script to run.

You will see a warning that the function or custom script you wrote is not “verified” by Google. If you are the person who wrote the script, it doesn’t matter and you can run it safely with your own Google or Google Workspace account.

To bypass this warning, simply select Advanced then select the Go to (unsafe) link below.

Finally, in the permissions window, select To permit to allow your custom features and scripts to run in your Google Account or Google Workspace.

You won’t have to repeat this process, only the first time you save or run your Google Apps Custom Scripts projects.

Access to your Google Script ID

A final note: you can provide your script to friends or colleagues so that they can use your script or add it as a library to their own script.

You can find your Script ID under the Settings icon in the far left navigation panel.

The script ID is in the identifications part to the right of Script ID.

As you can see, the Google Apps Script Editor is quite simple if you know how to access each feature you want to use. Just be sure to study the Google Apps Script documentation carefully so you can start learning how to write your scripts and all the features available.