从不同的电子表格收集数据后,在表单提交上发送电子邮件

时间:2016-05-16 22:33:12

标签: forms email google-sheets

我需要一些帮助来修复我当前的代码。这是我想要做的: 1.让用户提交Google表格(姓名,班级等) 2.获取这些答案并在单独的电子表格中搜索匹配的信息(同名,类等) 3.从匹配数据的同一行返回数据(父母姓名,电子邮件等) 4.发送电子邮件给父母,其中包含原始Google表单中的信息

我认为我有错误的地方是试图通过ID和搜索并返回值打开单独工作表的颂歌部分。我已经在下面的代码中包含了这一部分。

有没有人有任何建议?欢迎大家!谢谢你的时间:)

var sh = SpreadsheetApp.openById("17aA0SMZe1tarCUWM0ROdFmGoE3xsqrFRtYviHb85cqM");
Logger.log(sh.getName());
var sheet = sh.getActiveSheet();
var dataRange = sheet.getDataRange();
var values = dataRange.getValues();

for(var i = 0; i < values.length; i++) {
if(values[i][0] == dancersFirstName && values[i][1] == dancersLastName && values[i][2] == class)
{return values[i][7];}

var primaryContactFirstName = values[i][7];

if(values[i][0] == dancersFirstName && values[i][1] == dancersLastName && values[i][2] == class)
{return values[i][8];}

var primaryContactLastName = values[i][8];

if(values[i][0] == dancersFirstName && values[i][1] == dancersLastName && values[i][2] == class)
{return values[i][9];}

var primaryContactEmail = values[i][9];}


if(dancersFirstName + dancersLastName + class == values[i][0] + values[i][1] + values[i][2], toEmailAddress = primaryContactEmail);

整个代码如下:

function onFormSubmit(e) {

  var timestamp = e.values[0];

  var dancersFirstName = e.values[1];

  var dancersLastName = e.values[2];

  var class = e.values[3];

  var teacher = e.values[4]

  var attentiveness = e.values[5]

  var bodyPlacement = e.values[6];

  var memory = e.values[7];

  var corrections = e.values[8];

  var performance = e.values[9];

  var attendance = e.values[10];

  var comments = e.values[11];

  var placement = e.values[12];

  var teachersEmailAddress = e.values[13];

  var toEmailAddress = teachersEmailAddress;



  var sh = SpreadsheetApp.getActiveSpreadsheet().openbyID("17aA0SMZe1tarCUWM0ROdFmGoE3xsqrFRtYviHb85cqM");
  var values = sh.getDataRange().getValues();

  for(var i=0, iLen=values.length; i<iLen; i++) {

    if(values[i][0] == dancersFirstName && values[i][1] == dancersLastName && values[i][2] == class)
    {return values[i][7];}

    var primaryContactFirstName = values[i][7];

   if(values[i][0] == dancersFirstName && values[i][1] == dancersLastName && values[i][2] == class)
    {return values[i][8];}

    var primaryContactLastName = values[i][8];

   if(values[i][0] == dancersFirstName && values[i][1] == dancersLastName && values[i][2] == class)
    {return values[i][9];}

   var primaryContactEmail = values[i][9]; 

    if(dancersFirstName + dancersLastName + class == values[i][0] + values[i][1] + values[i][2], toEmailAddress = primaryContactEmail);}



  var subject = "2015-2016 Evaluation & Placement";

  var emailBody = "Dear" + dancersFirstName + " " + dancersLastName + " "+ "and" + primaryContactFirstName +" " + primaryContactLastName + " " +

  "Below is your dancer's evaluation and pleacement for" + class +

  "\n\nIs this dancer focused and attentive in class?" + attentiveness +

  "\n\nDoes this dancer understand and work towards correct body placement and alignment?" + bodyPlacement +

  "\n\nHas this dancer mastered the steps taught this year?  Is the dancer able to remember combinations?" + memory +

  "\n\nIs this dancer able to apply corrections?" + corrections +

  "\n\nIs this dancer able to dance with the music, perform with confidence, and display a commitment to performance quality?" + performance +

  "\n\nHas this dancer attended class regularly?" + attendance +

  "\n\nAdditonal Comments:" + comments +

  "\n\nPlacement for next year:" + placement +

  "\n\nThank you for dancing with us and enjoy your summer!" + teacher + "and The Moving Company Dance Center";

  MailApp.sendEmail(toEmailAddress,subject,emailBody);}

0 个答案:

没有答案