Class PromptResponse

  • PromptResponse represents the response from a prompt dialog in a Google App's user interface, containing user-entered text and the clicked button.

  • ThegetResponseText() method retrieves the text entered by the user in the dialog's input field.

  • ThegetSelectedButton() method identifies which button the user clicked to close the dialog, including the close button in the title bar.

PromptResponse

A response to aprompt dialog displayed in theuser-interface environment for a Google App. The response contains any text the user entered inthe dialog's input field and indicates which button the user clicked to dismiss the dialog.

// 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.constui=DocumentApp.getUi();constresponse=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());}elseif(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.');}

Methods

MethodReturn typeBrief description
getResponseText()StringGets the text that the user entered in the dialog's input field.
getSelectedButton()ButtonGets the button that the user clicked to dismiss the dialog.

Detailed documentation

getResponseText()

Gets the text that the user entered in the dialog's input field. The text is available even ifthe user closed the dialog by clicking a button with a negative connotation, like "Cancel" orthe close button in the dialog's title bar.getSelectedButton() can help to determinewhether the user intended the response text to be valid.

Return

String — The text that the user entered in the dialog's input field.


getSelectedButton()

Gets the button that the user clicked to dismiss the dialog. If the user clicked the closebutton that is included in every dialog's title bar, this method returnsButton.CLOSE.

Return

Button — The button that the user clicked.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.