0

My goal

Here is the documentation I'm trying to follow.

// Display a dialog box with a title, message, input field, and "Yes" and "No" buttons. The
// user can also close the dialog by clicking the close button in its title bar.
var ui = SpreadsheetApp.getUi();
var response = ui.prompt('Getting to know you', 'May I know your name?', ui.ButtonSet.YES_NO);

// Process the user's response.
if (response.getSelectedButton() == ui.Button.YES) {
  Logger.log('The user\'s name is %s.', response.getResponseText());
} else if (response.getSelectedButton() == ui.Button.NO) {
  Logger.log('The user didn\'t want to provide a name.');
} else {
  Logger.log('The user clicked the close button in the dialog\'s title bar.');
}

What I expect to happen and what happens instead

I expect the UI to display a dialog box with a title, message, input field, and "Yes" and "No" buttons. The user can also close the dialog by clicking the close button in its title bar.

But instead, nothing happens.

Steps to reproduce.

  1. Open a Google Sheet.
  2. Open Script Editor: Tools > Script editor
  3. Paste above code into script editor.
  4. Close script editor.
  5. Navigate to Google Sheet.

But as I mentioned, nothing actually happened.

How do I trigger the UI instance to initiate? What am I doing wrong?

1 Answer 1

1

Run this function:

function runIt() {
  var ui = SpreadsheetApp.getUi();
  var response = ui.prompt('Getting to know you', 'May I know your name?', ui.ButtonSet.YES_NO);
  if (response.getSelectedButton() == ui.Button.YES) {
    Logger.log('The user\'s name is %s.', response.getResponseText());
  } else if (response.getSelectedButton() == ui.Button.NO) {
    Logger.log('The user didn\'t want to provide a name.');
  } else {
    Logger.log('The user clicked the close button in the dialog\'s title bar.');
  }
}

After getting the function to run go look at the spreadsheet.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.