简体   繁体   中英

Prompt user input on Google Apps Script, error with `getUi()` method

I have been trying to write a script to display a prompt box that will take in user input for me to use to open a website.

I am trying the following code

var ui = SpreadsheetApp.getUi();
var response = ui.prompt('Please input email address', ui.ButtonSet.YES_NO);

But i get an error message saying

"The api method 'getUi' is not available yet in the new version of Google Sheets."

Does any know how I can work around this so that I can get the user input. I have searched everywhere for a solution but couldn't find any way to get user input.

Thank you.

I had the same problem. This error occurred for me when I tried to use the getUI() method in a google spreadsheet that was created prior to the "New" google spreadsheets. I don't know if the old sheets have been migrated yet to the new sheets, but in any event simply creating a new spreadsheet and copying my data across did the trick.

When I use your code in an onOpen() function of the New Google Spreadsheet, it's working for me without an error:

function onOpen() {

  var ui = SpreadsheetApp.getUi();
  var response = ui.prompt('Please input email address', ui.ButtonSet.YES_NO);

}

That above code works for me. It automatically shows a prompt when the sheet is opened or refreshed. So, we need more info to isolate the problem. Do you want the function to run when the Sheet opens, or is the code being triggered in some other way?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM