Skip to content

Commit 2a9bc04

Browse files
committed
Add dialogs example
1 parent a2ba1ba commit 2a9bc04

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

ui/dialogs.gs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
// [START apps_script_dialogs]
17+
/**
18+
* Creates a custom menu when a user opens a Spreadsheet.
19+
*/
20+
function onOpen() {
21+
SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
22+
.createMenu('Custom Menu')
23+
.addItem('Show alert', 'showAlert')
24+
.addToUi();
25+
}
26+
27+
/**
28+
* Shows an alert dialog.
29+
*/
30+
function showAlert() {
31+
var ui = SpreadsheetApp.getUi(); // Same variations.
32+
33+
var result = ui.alert(
34+
'Please confirm',
35+
'Are you sure you want to continue?',
36+
ui.ButtonSet.YES_NO);
37+
38+
// Process the user's response.
39+
if (result === ui.Button.YES) {
40+
// User clicked "Yes".
41+
ui.alert('Confirmation received.');
42+
} else {
43+
// User clicked "No" or X in the title bar.
44+
ui.alert('Permission denied.');
45+
}
46+
}
47+
// [END apps_script_dialogs]

0 commit comments

Comments
 (0)