Class PromptResponse | Apps Script | Google for Developers (original) (raw)
Class PromptResponse
Stay organized with collections Save and categorize content based on your preferences.
PromptResponse
A response to a [prompt](/apps-script/reference/base/ui#prompt%28String%29)
dialog displayed in the user-interface environment for a Google App. The response contains any text the user entered in the 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. const ui = DocumentApp.getUi(); const 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.'); }
Methods
Method | Return type | Brief description |
---|---|---|
getResponseText() | String | Gets the text that the user entered in the dialog's input field. |
getSelectedButton() | 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 if the user closed the dialog by clicking a button with a negative connotation, like "Cancel" or the close button in the dialog's title bar. [getSelectedButton()](#getSelectedButton%28%29)
can help to determine whether 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 close button that is included in every dialog's title bar, this method returns [Button.CLOSE](/apps-script/reference/base/button#CLOSE)
.
Return
[Button](/apps-script/reference/base/button)
— The button that the user clicked.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-12-02 UTC.