Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an alert message in Google app script while deploying a web app?

I am trying to create a web app using Google app script, that if you press a button, you may get an alert message.

In the home.gs file I tried this :

function let_user_decide()
{
Browser.msgBox('Greetings', 'Press Yes or No?', Browser.Buttons.YES_NO);
};

unfortunately I keep getting this when I press the button when I should get the alert message :

Exception: Cannot call Browser.inputBox() from this context.

Important to mention : my script is using Google spreadsheet but the msgBox should appear in the webapp! In addition, I use HTML

Any idea what am I doing wrong? And how can I fix it?

like image 327
Yair Saban Avatar asked Oct 13 '14 11:10

Yair Saban


People also ask

How do I Deploy a Google script to the web app?

At the top right of the script project, click Deploy > Test deployments. Next to "Select type," click Enable deployment types settings > Web app. Under the web app URL, click Copy. Paste the URL in your browser and test your web app.

What is trigger in Google App Script?

Triggers let Apps Script run a function automatically when a certain event, like opening a document, occurs. Simple triggers are a set of reserved functions built into Apps Script, like the function onOpen(e) , which executes when a user opens a Google Docs, Sheets, Slides, or Forms file.

How do I handle GET and POST HTTP requests in Google Apps Script?

Handle POST Requests with Google ScriptsThe callback function doPost is invoked when an HTTP POST request is make to your Google Script URL that is published as a web app with anonymous access. const doPost = (request) => { console. log(request); return ContentService. crateTextOutput(JSON.


1 Answers

Browser.msgBox is indeed only available in the spreadsheet interface, not in webapps.

You have a lot of alternatives to throw alerts but you should mention wether you use UiApp or HTML Service.

In UiApp you can create a popupPanel for example while in HTML you can throw alerts (throw new Error('sample alert')) or use JQuery Ui elements to do that.

like image 125
Serge insas Avatar answered Oct 28 '22 23:10

Serge insas