use*_*115 6 google-sheets google-apps-script
我有一个 Google Sheets 插件,它使用 App Script Ui 服务提供的对话框,即SpreadSheetApp.getUi().alert(...). 这通常工作正常,除非用户在 5 分钟内没有选择选项或关闭警报(假设他们切换到不同的选项卡或离开计算机),在这种情况下会引发“超时”异常。
我的代码:
var ui = SpreadsheetApp.getUi();
var response = ui.alert(msg, ui.ButtonSet.YES_NO);
return (response == ui.Button.YES);
Run Code Online (Sandbox Code Playgroud)
Apps 脚本执行记录中的错误:
[18-02-27 16:40:18:080 EST] Starting execution
[18-02-27 16:40:18:096 EST] SpreadsheetApp.getUi() [0 seconds]
[18-02-27 16:45:18:160 EST] Ui.alert([Are you sure you want to delete this
thing?, YES_NO]) [300.063 seconds]
[18-02-27 16:45:18:166 EST] Execution failed: Timed out waiting for user
response (line 289, file "Code") [300.066 seconds total runtime]
Run Code Online (Sandbox Code Playgroud)
抛出异常后,警报仍然可见,并且如果用户返回并点击“是”,上述函数仍然不会返回 true。它只是关闭对话框,用户必须重试。
如果我只在警报周围添加一个 try/catch,用户将不会知道警报在 5 分钟后变得毫无用处。理想情况下,我可以调用类似的方法alert.close(),但我找不到类似的方法。有没有更好的方法来处理这个问题,或者我应该改用 HTML/javascript 来发出警报?
| 归档时间: |
|
| 查看次数: |
1173 次 |
| 最近记录: |