Displaying notifications in Google Sheets using toasts
A toast is a notification that provides some contextual information to the user in an unobtrusive manner. A toast notification will automatically disappear after a few seconds.
In Google Sheets, toast notifications are displayed in the bottom right corner of the screen.
It's really simple to write the code to display toast notifications. For example, the code to display the prompt in the above image is just one line.
🛈 Note
If you've never worked with Apps Script before, I've written an article that explains how to create your first apps script. I've also written a series of articles to teach you how to code using Google Sheets and Apps Script.
function toastMessage() {
SpreadsheetApp.getActive().toast("Message");
}
You can also include a title along with the message.
function toastMessageTitle() {
SpreadsheetApp.getActive().toast("Message", "Title");
}
★ Tip: Use relevant emojis to make your notifications stand out
You can use emojis to make your notifications stand out and to help your users understand the type of notification being displayed. Here are some emojis that you can use:
⚠️: Warning
⏰: Something that is time sensitive
💡: An idea or a recommendation
🎉: An accomplishment
👍: Thumbs up
⚙️: Settings related
The code below shows you how to include emojis in a toast notification.
function toastMessageTitle() {
SpreadsheetApp.getActive().toast("Could not import data from the URL.", "⚠️ Error");
}
Running the above code will display the following toast notification. The emoji provides visual feedback to the user to help them understand that some sort of error has occurred.
Finally, you can configure the number of seconds the notification should be shown.
function toastMessageTimeout() {
// Display the toast for 15 seconds
SpreadsheetApp.getActive().toast("Message", "Title", 15);
}
Conclusion
In this tutorial, you learned how to display toast notifications in Google Sheets using Google Apps Script.
Thanks for reading.