Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between ui.alert and Browser.msgBox?

When working with Google Scripting, there's a Browser.msgBox(); (Link) and ui.alert(); (Link). What is the difference between the two? They appear to do the exact same thing.

There are more methods within, such as Browser.inputBox(); and ui.prompt(); which again, appear to be identical.

like image 246
UtahJarhead Avatar asked Apr 29 '15 22:04

UtahJarhead


People also ask

Can you add a pop up message to Google Sheets?

To display a pop up alert message, you need to write some code using Google Apps Script. Don't worry, it is very simple and straightforward to do that. If you've never worked with Apps Script before, I've written an article that explains how to create and run your first apps script.

What is Apps Script in Google Sheets?

Apps Script allows you to connect Google Forms with Google Sheets through Forms and Spreadsheet services. This feature can automatically create a Google Form based on data in a spreadsheet. Apps Script also enables you to use triggers, such as onFormSubmit to perform a specific action after a user responds to the form.

How do I debug a script in Google Sheets?

To run the script in debug mode, at the top of the editor click Debug. Before the script runs the line with the breakpoint it pauses and displays a table of debug information. You can use this table to inspect data like the values of parameters and the information stored in objects.


1 Answers

The Browser Class is only available to a Spreadsheet. The Ui Class can be more widely used. Unfortunately, the documentation for Class Ui only shows an example of the getUi() method with the SpreadsheetApp Class. But getUi() is available to DocumentApp.

DocumentApp.getUi()

get Ui Class

And to:

FormApp.getUi()

If you try to call Browser.msgBox() from the wrong context, you'll get an error:

Cannot call Browser.msgBox() from this context; have you tried Logger.log() instead?

Browser.msgBox() is easier to use in a Spreadsheet script. You don't need to first use var ui = SpreadsheetApp.getUi();

To compare:

Browser.msgBox('prompt here');
SpreadsheetApp.getUi().prompt('prompt here');
like image 85
Alan Wells Avatar answered Oct 01 '22 19:10

Alan Wells