【发布时间】:2019-01-07 06:39:17
【问题描述】:
我有一个电子表格,我在其中打开一个带有订单详细信息的侧边栏,然后出现一个警告,询问用户是否准备好发送邮件。如果用户选择取消,我想停止整个脚本并关闭侧边栏。 google.script.host.close 给出了无法从未定义的错误中读取属性“脚本”。 我如何无需手动关闭侧边栏?
// Display a modal dialog box in sidebar with custom HtmlService content to preview the order.
var htmlOutput = HtmlService.createHtmlOutput('<h1>'+ supplier + '</h1><br/>' + previewOrder)
.setTitle('Order Details');
SpreadsheetApp.getUi().showSidebar(htmlOutput);
// now also show an alert asking if you want to send the mail
var ui = SpreadsheetApp.getUi();
var response = ui.alert('Confirm Sending','You are about to send this order to '+ supplier + ' (' + emailAddress + ') - are you sure?', ui.ButtonSet.YES_NO_CANCEL);
// Process the user's response.
if (response == ui.Button.YES) {
var subject = "Order for Tomorrow ";
MailApp.sendEmail(emailAddress,subject + dayname + " - " + Utilities.formatDate(tomorrow, "GMT+2", "d MMM") + "" ,emailBody, {to: emailAddress,cc: ccEmailAddress, htmlBody: emailBody});
}
else if (response == ui.Button.NO) {
//if user chooses NO then ignore and continue the loop
} else {
//close the sidebar
SpreadsheetApp.getUi().google.script.host.close();
//cancel the script
return;
}
【问题讨论】:
-
为什么不在侧边栏上放一个按钮来预览订单并使用对话框客户端来预览订单,然后当他们取消对话框时,您可以同时关闭侧边栏和对话框.我经常使用 JQuery UI - Dialog,它们相当容易使用。如果您需要来自服务器的数据,您可以使用 google.script。使用成功处理程序运行以获取数据。
标签: google-apps-script web-applications sidebar