S
S
Sergey Ryazanov2021-10-22 11:07:06
Google Apps Script
Sergey Ryazanov, 2021-10-22 11:07:06

How to display a message in the Google Scripts editor using Browser.msgBox()?

I just started studying google scripts, and on the first attempt to display "Hello world!" I got an error that I don't know how to fix.

Here is the suggested code from the tutorial:

function helloWorldBrowseer() {
  Browser.msgBox("Hello world!");
}

When running the script, the editor gives an error:
10:58:29
Error
Exception: Cannot call Browser.msgBox() from this context; have you tried Logger.log() instead?

The editor prompts me to output a message via Logger.log(). So the message is displayed without problems. But why doesn't the textbook example with a message display via Browser.msgBox() work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grigory Boev, 2021-10-22
@ProgrammerForever

If the script is not attached to anything (document) then it can be assumed that it is executed by itself, without UI . Where to display the message? So he offers to write to the logger.
If you really need to view the message, then do it from a script attached to a document, such as a table. And there already take the document, its UI and call alert ()
SpreadsheetApp.getUi().alert("h,w!");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question