2. Create an Alert in a Document

Playback Speed:

In this video, you will write the code for a personalized alert.

Creating an alert is the first step to making a pop-up message that greets your readers when they open your document.

You’ll work in your “Opening Message” project in the Script Editor.

First, tell the code to show your message in your document.

Between the highlighted curly braces, type “DocumentApp”...

with a capital D and A, and no spaces between the words.

Type a period at the end of “DocumentApp.”

An autocomplete menu appears.

If the menu doesn’t appear when you type a period, check your spelling and capitalization.

The autocomplete menu keeps you from having to type or remember every piece of code.

Scroll down the autocomplete menu, and select get UI This tells the computer to “get” the “user interface,” or the screen you type in, from Google Docs.

Type open and closed parentheses.

The line of code looks like this.

As you write, be precise.

One wrong character will keep your code from working properly.

It’s okay to make mistakes, though.

You can always go back and modify your code.

At the end of that line of code, type a period.

The autocomplete menu appears again.

Next, write code that will show a message.

This is called an alert.

From the autocomplete menu, choose alert.

Type open and closed parentheses.

Take a look at your code so far.

It reads, “Use the Google Docs App and the display screen for the document to make an alert box appear.”

Next, customize your code by typing a unique message for the alert.

Put double quotation marks around your message.

This is called a parameter.

In computer science a...

In this case, the parameter tells the computer the exact text to display in the alert.

The code that gives the computer instructions has to be exact.

But the text you type inside the parentheses can be anything you like.

Write your own message that fits your document and shows off your personality.

Save your code.

Then, run it.

Switch back to the tab for your "Research Notes."

There’s the window. Perfect.

If the alert doesn’t show, or if you see an error message in the Script Editor, check the code carefully.

Check your capitalization.

Lookfor extra spaces or periods...

and make sure the text of the alert is inside double quotation marks.

If you’ve checked your code and the alert still doesn’t appear or you get an error message, ask your neighbor for help.

They might see an error you missed.

Computer scientists often team up to create and check code.

Sometimes two people working together can find and solve problems faster.


  1. Type DocumentApp to tell the computer where the prompt will appear.
  2. Use the autocomplete menu to get the UI and to add an alert.
  3. Type your unique alert message.
  4. Save and run the code.
  5. *NOTICE: THERE IS A KNOWN ISSUE WITH THIS LESSON. When you first open your document in Google Docs, the onOpen popup message is not opening automatically as described in the video. This error is due to changes in the Apps Script programming that is fixed in the final video in this lesson. However, if you manually run the script and the popup message appears, then your code is correct.*