Google Apps Script: Create an Alert

Create an alert

Google Apps Script allows you to customize Google Apps. Part of your script can alert the user to provide them information or inform them that the script ran correctly. Here is the sample code to create an alert.

Script Editor

In a Google Sheets spreadsheet or in a Google Doc use the Tools menu to select “Script editor.”
Script Editor

UI

An alert is part of the user interface (UI). Define a variable to call the UI. Notice that the i in Ui is lowercase.

var ui = SpreadsheetApp.getUi();

After defining the UI, call an alert in the next line. Start with the ui variable you just defined. Type a period and choose alert from the options. Within the parenthesis is the message you wish to display. Remember that all text strings must go in single quotations.

ui.alert(‘text’);

Sample Script

Prompt

A prompt is similar to an alert; however, it allows the the user to input a value. Use prompt instead of alert for the method. Optionally you can define the buttons on the prompt.

var ui = SpreadsheetApp.getUi();
ui.prompt(‘What is your name?’, ui.ButtonSet.YES_NO);

Prompt Response

Asking for information is not very useful if you do not collect the response. Define a variable for the prompt. I use var = ask. In the next line define a variable for the response. The method getResponseText() will allow you to use the response to the prompt in your script.

function prompt(){

var ui = SpreadsheetApp.getUi();
var ask = ui.prompt(‘What is your name?’, ui.ButtonSet.YES_NO);
var response = ask.getResponseText();
}

Sample

CLICK HERE for a spreadsheet with an Add-On “Alert sample” to demonstrate alerts and prompts.

Leave a Comment

© 2026 All Rights Reserved.

Get effective EdTech strategies from Alice Keeler to build a more student centered classroom. Includes unique resources and templates.

Recent Teacher Tech Blog Posts

💥 FREE OTIS WORKSHOP

Join Alice Keeler, Thursday April 28th or register to gain access to the recording.
Create a free OTIS account.

Join Alice Keeler for this session for teaching with AI

Imagine having a team of teaching assistants who already know your syllabus and exactly how you like to give feedback. Join Google Certified Innovator Alice Keeler to learn how to use Google Gems to build a powerful collection of custom AI tools. We will explore how to engineer specific instructions so you can create a Grading Assistant or a Classroom Policy Manager that works for you. You will also learn how to leverage Gems shared by other educators to instantly expand your toolkit. This session is about super-powering your teaching by automating the routine tasks so you can focus on the students.

Exit this pop up by pressing escape or clicking anywhere off the pop up.