我有这个Google Apps脚本,可以向我在电子表格中选择的人员发送带有请求的电子邮件:
function sendRequestEmail() {
var data = SpreadsheetApp.openById(SPREADSHEET);
if(!employee_ID) {
employee_ID = getCurrentRow();
if (employee_ID == 1) {
var employee_ID = Browser.inputBox("Você precisa selecionar um assistido?", "Choose a row or type its number here:", Browser.Buttons.OK_CANCEL);
}
}
// Fetch variable names
// they are column names in the spreadsheet
var sheet = data.getSheets()[0];
var columns = getRowAsArray(sheet, 1);
Logger.log("Processing columns =" + columns);
var employeeData = getRowAsArray(sheet, employee_ID);
Logger.log("Processing employeeData = " + employeeData);
// Assume first column holds the name of the person
var email2Send = "[email protected]";
var title = "Request by email";
var name = employeeData[0];
var mother_name = employeeData[1];
var message = "Hi, I have a request for you, " + name + ", this is... example";
// HERE THE
// CONFIRMATION BUTTON!!!
MailApp.sendEmail(email2Send, title, message);
}
而且,在发送电子邮件之前,我需要一个确认按钮,如下所示:
function showConfirmation(name, email2Send) {
var app = UiApp.createApplication().setHeight(150).setWidth(250);
var msg = "Do you confirm the request to " + email2Send + " about " + name + "?";
app.setTitle("Confirmation of request");
app.add(app.createVerticalPanel().add(app.createLabel(msg)));
var doc = SpreadsheetApp.getActive();
doc.show(app);
}
因此,如果用户按“确定”,则该应用程序将执行该行MailApp.sendEmail(email2Send, title, message);
并发送电子邮件。
我必须承认我的无知。我正在阅读有关处理程序的《 Google Apps脚本》(詹姆斯·费雷拉(Oreilly),詹姆斯·费雷拉(James Ferreira))一书的第4章。我尝试使用Google文档中提供的示例(已经删除了代码!)。但是我遇到了一个我无法理解的错误。
使用的代码是以下示例:
var ui = DocumentApp.getUi();
var 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) ... DO THIS
我在这个简单的项目中有一些紧迫性,所以请原谅我在研究更多答案之前先问这个问题(我在寻找答案的同时在寻找它)。那么,如何在此代码中使用确认/取消按钮?
您显示的代码段是针对文档嵌入式UI的,电子表格上下文的等效(很好...几乎)类是Browser.MsgBox(prompt,buttons)
,请参见此处的文档,它将比创建Ui +处理函数更简单...即使布局和外观是相当基本的,它既简单又有效。
在您的代码中,它变为:
...
var confirm = Browser.msgBox('send confirmation','Are you sure you want to send this mail ?', Browser.Buttons.OK_CANCEL);
if(confirm=='ok'){ MailApp.sendEmail(email2Send, title, message)};
...
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句