Class PromptResponse
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
프롬프트응답
Google 앱의 사용자 인터페이스 환경에 표시되는 prompt
대화상자에 대한 응답입니다. 응답에는 사용자가 대화상자의 입력란에 입력한 텍스트가 포함되며 사용자가 대화상자를 닫기 위해 클릭한 버튼을 나타냅니다.
// 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.');
}
자세한 문서
getResponseText()
사용자가 대화상자의 입력란에 입력한 텍스트를 가져옵니다. 사용자가 '취소' 또는 대화상자의 제목 표시줄에 있는 닫기 버튼과 같이 부정적인 의미를 지닌 버튼을 클릭하여 대화상자를 닫은 경우에도 텍스트를 사용할 수 있습니다. getSelectedButton()
는 사용자가 응답 텍스트를 유효하게 하려는 의도가 있었는지 판단하는 데 도움이 됩니다.
리턴
String
: 사용자가 대화상자의 입력란에 입력한 텍스트입니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003e\u003ccode\u003ePromptResponse\u003c/code\u003e objects store user input and button selections from prompts in Google Apps Script UI.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetResponseText()\u003c/code\u003e retrieves the text entered by the user in the prompt's input field.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetSelectedButton()\u003c/code\u003e identifies which button the user clicked to close the prompt (e.g., YES, NO, CLOSE).\u003c/p\u003e\n"],["\u003cp\u003eThis data allows scripts to react differently based on user interaction with the prompt dialog.\u003c/p\u003e\n"]]],[],null,["# Class PromptResponse\n\nPromptResponse\n\nA response to a [prompt](/apps-script/reference/base/ui#prompt(String)) dialog displayed in the\nuser-interface environment for a Google App. The response contains any text the user entered in\nthe dialog's input field and indicates which button the user clicked to dismiss the dialog.\n\n```javascript\n// Display a dialog box with a title, message, input field, and \"Yes\" and \"No\"\n// buttons. The user can also close the dialog by clicking the close button in\n// its title bar.\nconst ui = DocumentApp.getUi();\nconst response = ui.prompt(\n 'Getting to know you',\n 'May I know your name?',\n ui.ButtonSet.YES_NO,\n);\n\n// Process the user's response.\nif (response.getSelectedButton() === ui.Button.YES) {\n Logger.log('The user\\'s name is %s.', response.getResponseText());\n} else if (response.getSelectedButton() === ui.Button.NO) {\n Logger.log('The user didn\\'t want to provide a name.');\n} else {\n Logger.log('The user clicked the close button in the dialog\\'s title bar.');\n}\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|---------------------------------------------|----------------------------------------------|------------------------------------------------------------------|\n| [getResponseText()](#getResponseText()) | `String` | Gets the text that the user entered in the dialog's input field. |\n| [getSelectedButton()](#getSelectedButton()) | [Button](/apps-script/reference/base/button) | Gets the button that the user clicked to dismiss the dialog. |\n\nDetailed documentation\n----------------------\n\n### `get``Response``Text()`\n\nGets the text that the user entered in the dialog's input field. The text is available even if\nthe user closed the dialog by clicking a button with a negative connotation, like \"Cancel\" or\nthe close button in the dialog's title bar. [getSelectedButton()](#getSelectedButton()) can help to determine\nwhether the user intended the response text to be valid.\n\n#### Return\n\n\n`String` --- The text that the user entered in the dialog's input field.\n\n*** ** * ** ***\n\n### `get``Selected``Button()`\n\nGets the button that the user clicked to dismiss the dialog. If the user clicked the close\nbutton that is included in every dialog's title bar, this method returns [Button.CLOSE](/apps-script/reference/base/button#CLOSE).\n\n#### Return\n\n\n[Button](/apps-script/reference/base/button) --- The button that the user clicked."]]