如何在Google Apps脚本电子表格嵌入式脚本中使用确认按钮?

工艺学徒

我有这个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

我在这个简单的项目中有一些紧迫性,所以请原谅我在研究更多答案之前先问这个问题(我在寻找答案的同时在寻找它)。那么,如何在此代码中使用确认/取消按钮?

塞尔萨·印萨斯(Serge insas)

您显示的代码段是针对文档嵌入式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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Google Apps脚本中使用本机电子表格功能?

Google Apps脚本-无法在App(电子表格等)中使用HTML服务“ createTemplateFromFile”吗?

Google Apps脚本-在= IMAGE()电子表格公式中使用云端硬盘中文件的网址

如何在Google Apps脚本中获取发布到网络电子表格的ID

如何使用Google Photos API方法:电子表格的Google Apps脚本中的mediaItems.search

如何使用Apps脚本通过电子表格数据自动填充HTML字段?

Google Apps脚本-如何在onFormSubmit(Google表单事件)中的目标电子表格中获取相应的记录?

如何使用Apps脚本复制过滤的电子表格数据

如何使用Google Apps脚本应用电子表格过滤器?

在WorkBook中使用另一个电子表格中的= UNIQUE-Google Apps脚本

如何使用Google Apps脚本引用外部电子表格

Google Apps脚本如何共享特定的电子表格?

如何在Google Apps脚本中的不同电子表格之间复制条件格式

如何在另一个电子表格中使用Google Apps脚本?

使用Google电子表格脚本复制并粘贴

Google电子表格脚本

Google Apps脚本,使用格式将一个电子表格复制到另一电子表格

从电子表格中修改另一个电子表格:Google Apps脚本

使用Google Apps脚本设置电子表格单元格格式

使用Google Apps脚本编辑Google电子表格

如何使用Google Apps脚本向电子表格单元格添加链接

使用Google Apps脚本将Google电子表格导出为JSON(或XML)格式

在Google时区(而不是电子表格时区)中使用Google Apps电子表格脚本的日期

使用 Google Apps 脚本确认电子表格列中的值

如何在 Google 电子表格中使用自定义脚本进行条件格式设置?

如何使用 Apps 脚本将多个电子表格中特定列的数据导入到一个电子表格中?

UrlFetchApp 服务器使用 Google Apps 脚本锁定特定电子表格

使用 Apps 脚本从 Google 电子表格向 LINE 通知发送消息

如何根据活动电子表格 Google Apps 脚本中的数据创建多个电子表格?