Class PromptResponse Stay organized with collections Save and categorize content based on your preferences.
Page Summary
PromptResponse represents the response from a prompt dialog in a Google App's user interface, containing user-entered text and the clicked button.
The
getResponseText()method retrieves the text entered by the user in the dialog's input field.The
getSelectedButton()method identifies which button the user clicked to close the dialog, including the close button in the title bar.
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
| Method | Return type | Brief description |
|---|---|---|
get | String | Gets the text that the user entered in the dialog's input field. |
get | Button | Gets 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.get 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.