Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Browser.msgBox responses in google spreadsheet app?

I am trying get the response of the user to do another action.

Browser.msgBox('Greetings', 'hello world', Browser.Buttons.YES_NO);
if (response == Browser.Buttons.YES) {
Logger.log('The user clicked "Yes."');
} else {
Logger.log('The user clicked "No" or the dialog\'s close button.');
}

but this does not work. "response is not defined" error shows up. How do I get the response?

like image 437
Neo Avatar asked Dec 18 '22 23:12

Neo


2 Answers

Take a closer look at the documentation. It returns a String containing the "lower case text of the button that is clicked by the user (or 'cancel' for a dismissed dialog)".

You also need to save the return value in the response variable.

var response = Browser.msgBox('Greetings', 'hello world', Browser.Buttons.YES_NO);
if (response == "yes") {
  Logger.log('The user clicked "Yes."');
} else {
  Logger.log('The user clicked "No" or the dialog\'s close button.');
} 
like image 115
Diego Avatar answered Dec 28 '22 07:12

Diego


This is how it works :

  var response = Browser.msgBox('Greetings', 'hello world', Browser.Buttons.YES_NO);
  Logger.log(response);
  if (response == "yes") {
    Logger.log('The user clicked "Yes."');
  } else {
    Logger.log('The user clicked "No" or the dialog\'s close button.');
  }

Browser method that ask for a response option returns a string, you could have used the logger like in the code above to check it. So we have to use a condition on that string to check the result.

like image 43
Serge insas Avatar answered Dec 28 '22 06:12

Serge insas