2

I am creating an new Google Apps Script about GDrive/New/More/Google Apps Script.

enter image description here

The script is running perfect and on the end my intention is to send a Info on the Desk.

When I am using this line:

Browser.msgBox("TEST");

I get the error back:

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

Logger.log can't be the solution, because I don't see the result on the desktop, but only in the log files.

Is there another solution or is it possible to get a simply example what I can do?

TheMaster
  • 45,448
  • 6
  • 62
  • 85
J. Doe
  • 151
  • 12
  • 1
    I think this has to do with the way you created your Appscript Project: to use `Browser.msgBox()` your Appscript project has to be "attached" to another tools like Docs, Sheets or Slides. – t9dupuy Aug 19 '22 at 07:21
  • When I add my simple script to e.g. a sheet: function myFunction() { Browser.msgBox("TEST"); } I get no Message on the Desktop when I start the script about a Trigger. When I start the script about GSheet it works fine. – J. Doe Aug 19 '22 at 10:17
  • 1
    Not possible.... – TheMaster Aug 19 '22 at 11:35
  • Do you have another idea How I can do? – J. Doe Aug 19 '22 at 12:35
  • You're trying to display a message box from a trigger? What if the sheet or doc is out of context (closed)? To handle any context use `Logger.log("TEST")` and then check the execution log of the spreadsheet or doc its bound to. – TheWizEd Aug 19 '22 at 12:53
  • Just put the script inside a spreadsheet and you will get the user interface for alert messages. – Yuri Khristich Aug 19 '22 at 12:56
  • Please add all the relevant details to the question body, including what type the trigger are you using. – Rubén Aug 19 '22 at 17:27

1 Answers1

1

In this case Browser.msgBox is a method for the Browser class, this class is specifically meant to be used in Spreadsheets as stated in the documentation:

Class Browser This class provides access to dialog boxes specific to Google Sheets.

The methods in this class are only available for use in the context of a Google Spreadsheet.

If you want a notification you could use either the Browser.msgBox method or the Toast method, either way they both need to be applied in a Spreadsheet in order to work.

Gabriel Carballo
  • 1,278
  • 1
  • 3
  • 9
  • When I create my script to open before a Spreadsheet and then to make a dialogbox - i get the same fault. I there realy no chance? – J. Doe Aug 19 '22 at 15:14
  • The 2 type of dialog boxes that I mentioned are only used in a Google Spreadsheet, if you were looking to have a notification send from app script by itself I'm afraid that there won't be a feature for that, you may want to submit a feature request in the [IssueTracker](https://issuetracker.google.com/) – Gabriel Carballo Aug 19 '22 at 21:55
  • It is a pity that this does not exist "yet". Nevertheless, thanks for the help. – J. Doe Aug 22 '22 at 08:28
  • If this answered your question, please click the accept button on the left (check icon). By doing so, other people in the community, who may have the same concern as you, will know that theirs can be resolved. If the accept button is unavailable to you, feel free to tell me. [How to accept answer](https://stackoverflow.com/help/accepted-answer) – Gabriel Carballo Aug 22 '22 at 13:57