只需要根据单元格N中的电子邮件地址通过电子邮件发送最新的Google表单已提交数据

时间:2019-07-01 15:06:23

标签: google-apps-script google-sheets

我想要一个简单的脚本,该脚本将最新的Google表单数据发送到根据If语句创建的电子邮件地址,该电子邮件地址是根据收集数据的Google列J(第9行)中的运营商标题创建的。不幸的是,我不能共享正在使用的工作表,因为我的公司不允许我们在公司外部共享。

    function CustomEmail() {
  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Responses');
  var startRow = 2;
  var numRows = 700; 
   var dataRange = ss.getRange("A2:Q700"); 
   var data = dataRange.getValues();
  var emailSent = "Email Sent";
  for (var i = 0; i < data.length; ++i) {
     var carrier = data[i][9];//armored car carrier  
    if (carrier === 'Dunbar/Brinks'){ 
    var  Email = ("xxx@xxx.com");}
    else if (carrier === 'GARDA'){ 
    var  Email = ("xxx@xxx.com");}
    else if (carrier === 'Loomis'){ 
    var  Email = ("xxx@xxx.com");}
    else{ 
    var Email = '';
    }   
  var subject= "New Armored Car Missed Pick-UP";//subject for the email will be// 
    if (Email.length>0);{  
    var row = data[i];      
    var date = row[11];   
    var store = row[2];//Store Name    
    var address = row[3];//Address    
    var city = row[4];//City    
    var state = row[5];//state    
    var manager = row[6];//manager name    
    var reason = row[10];//reason  
    var emailBody = "New Armored Car Pick-Up Report from: " +store+ "\nDate of Missed Pick-Up: " +date+ "\nAddress: " +address+ "\nCity: " +city+ "\nState: " +state+ "\nManager: " +manager+ "\nCarrier: " +carrier+ "\nReason: " +reason;
    var isEmailSent = row[16];
  if (isEmailSent != "Email Sent") {
     MailApp.sendEmail(Email, subject, emailBody); 
    ss.getRange(startRow + i,17).setValue(emailSent);
    };
   };
 }
 }

1 个答案:

答案 0 :(得分:0)

在假期周末读了很多书之后,我重写了脚本,现在脚本可以按照我们想要的方式工作。谢谢大家的协助。

 var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Responses');
  var startRow = 2;
  var numRows = 700; 
   var dataRange = ss.getRange("A2:Q700"); 
   var data = dataRange.getValues();
  var emailSent = "Email Sent";
  for (var i = 0; i < data.length; ++i) {

//中间的电子邮件正文///

var isEmailSent = row[16];
  if (isEmailSent != "Email Sent") {
     MailApp.sendEmail(Email, subject, emailBody); 
    ss.getRange(startRow + i,17).setValue(emailSent);
    };
   };
 }
 }