response.getselectedbutton() is not a function?

Stack Overflow Asked by Fishy Apprentice on November 15, 2020

I am in school and trying to code a google apps script where I have a function bound to a doc with a custom menu that can create a new doc with the date, subject, and email it to the teacher of said subject. All was going according to plan until I decided to make it so that if I hit cancel instead of OK in one of the parameters I would get the default value of that parameter if I had not hit edit parameters so I could easily only change 1 or 2 things. The function works spotlessly, but now what’s happening is I can’t get the selected button for the alert that asks me if I want to edit parameters.

It just says

"TypeError: response.getSelectedButton is not a function"

and won’t let me run my function. Here’s my code for the function. This has worked fine for me in the past and I’m really not sure why it doesn’t work now.

function Mathdoc() {   var ui = DocumentApp.getUi();   
       var d = new Date();
var s = (d.getDate()) + '/' + (d.getMonth()+1) + '/' + d.getFullYear();
                  var response = ui.alert( 'Change parameters?', ui.ButtonSet.YES_NO);
  if (response.getSelectedButton() == ui.Button.YES) {  insert all my other code here}

Is there a glitch or something I’m missing? I’m new to JS and fairly new to web design altogether.

2 Answers

There is no method named getSelectedButton(). The ui.alert() just returns the button and nothing else

function Mathdoc() {   
  var ui=DocumentApp.getUi();   
  var d = new Date();
  var s = (d.getDate()) + '/' + (d.getMonth()+1) + '/' + d.getFullYear();
  var response=ui.alert( 'Change parameters?', ui.ButtonSet.YES_NO);
  if (response==ui.Button.YES) {  insert all my other code here}

Look at example here

Correct answer by Cooper on November 15, 2020

Nope, this function doesn't exist. Basically if you type a function on google and don't find anything, it means the function doesn't exist

EDIT : If you have an error message that says it doesn't exist, it means that the function really doesn't exist or that the library containing the function is missing. But in your case the function doesn't exist

Answered by R-son on November 15, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP