是/否用户提示继续或停止脚本

Cri*_*una 3 google-apps

我有这个很好的谷歌应用程序脚本,它工作正常,但它会导致我的谷歌电子表格中的工作表被删除,因此我希望脚本以是/否提示开始,询问“你确定要关闭工作吗”。如果他说是,很好,继续,如果不是,退出脚本。

有任何想法吗?提前致谢 !

Cri*_*una 5

找到这个

 // Display a dialog box with a message and "Yes" and "No" buttons. The user 
can also close the
 // dialog by clicking the close button in its title bar.
 var ui = SpreadsheetApp.getUi();
 var response = ui.alert('Are you sure you want to continue?', 
ui.ButtonSet.YES_NO);

 // Process the user's response.
 if (response == ui.Button.YES) {
   Logger.log('The user clicked "Yes."');
 } else {
   Logger.log('The user clicked "No" or the close button in the dialog\'s 
title bar.');
 }
Run Code Online (Sandbox Code Playgroud)