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

Forms 从不同的电子表格收集数据后发送表单提交电子邮件,forms,email,google-sheets,Forms,Email,Google Sheets,我需要一些帮助来修复我当前的代码。以下是我试图做的: 1.让用户提交Google表单(名称、类等) 2.获取这些答案并在单独的电子表格中搜索匹配信息(相同的名称、类别等) 3.从找到匹配数据的同一行返回数据(父母姓名、电子邮件等) 4.向家长发送一封包含原始谷歌表单信息的电子邮件 我认为我犯错误的地方是ode的一部分,它试图通过ID打开单独的工作表,并搜索和返回值。我在下面包含了这段代码 有人有什么建议吗?欢迎大家!谢谢你抽出时间:) var sh=SpreadsheetApp.openById

我需要一些帮助来修复我当前的代码。以下是我试图做的: 1.让用户提交Google表单(名称、类等) 2.获取这些答案并在单独的电子表格中搜索匹配信息(相同的名称、类别等) 3.从找到匹配数据的同一行返回数据(父母姓名、电子邮件等) 4.向家长发送一封包含原始谷歌表单信息的电子邮件

我认为我犯错误的地方是ode的一部分,它试图通过ID打开单独的工作表,并搜索和返回值。我在下面包含了这段代码

有人有什么建议吗?欢迎大家!谢谢你抽出时间:)

var sh=SpreadsheetApp.openById(“17aA0SMZe1tarCUWM0ROdFmGoE3xsqrFRtYviHb85cqM”);
Logger.log(sh.getName());
var sheet=sh.getActiveSheet();
var dataRange=sheet.getDataRange();
var values=dataRange.getValues();
对于(变量i=0;i
整个代码如下:

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);}
函数onFormSubmit(e){
var timestamp=e.values[0];
var dancersFirstName=e.values[1];
var=e.values[2];
var等级=e.值[3];
var教师=e.价值观[4]
var关注度=e.值[5]
var bodyPlacement=e.值[6];
var内存=e.值[7];
var校正=e.值[8];
var性能=e.值[9];
var出席率=e.值[10];
var注释=e.值[11];
var位置=e.值[12];
var teachersEmailAddress=e.values[13];
var toEmailAddress=教师电子邮件地址;
var sh=SpreadsheetApp.getActiveSpreadsheet().openbyID(“17aA0SMZe1tarCUWM0ROdFmGoE3xsqrFRtYviHb85cqM”);
var values=sh.getDataRange().getValues();

对于(var i=0,iLen=values.length;iis这是一个不完整的函数体吗?这个脚本本身没有什么意义,每次在似乎是全局环境中返回某个内容时,都要执行三次相同的检查,最后执行另一个if子句,该子句有第二个参数,但没有结果。我已将整个代码包含在问题的我不确定是否可以一次返回三个值,这就是为什么我重复了三次相同的检查(我在编写代码方面非常新手).最后,我试图做最后一次检查,以确保表单上提交的名称和类与电子表格中选定的名称和类相同。您知道如何正确执行此操作吗?我已经尝试了一段时间,尝试了不同的方法,但没有真正实现:/n当您返回时,退出func注意,在返回语句执行后,代码主体中没有任何内容。只需将所有赋值语句放在if子句的主体中。非常感谢您的响应和帮助!我像您所说的那样更改了if子句。但是,电子邮件仍然没有发送。您还有其他建议吗?我已经包含了新的if子句在下面的评论中(var i=0,iLen=values.length;iis这是一个不完整的函数体吗?这个脚本本身没有什么意义,每次在似乎是全局环境中返回某个内容时,都要执行三次相同的检查,最后执行另一个if子句,该子句有第二个参数,但没有结果。我已将整个代码包含在问题的我不确定是否可以一次返回三个值,这就是为什么我重复了三次相同的检查(我在编写代码方面非常新手).最后,我试图做最后一次检查,以确保表单上提交的名称和类与电子表格中选定的名称和类相同。您知道如何正确执行此操作吗?我已经尝试了一段时间,尝试了不同的方法,但没有真正实现:/n当您返回时,退出func注意,在返回语句执行后,代码主体中没有任何内容。只需将所有赋值语句放在if子句的主体中。非常感谢您的响应和帮助!我像您所说的那样更改了if子句。但是,电子邮件仍然没有发送。您还有其他建议吗?我已经包含了新的if子句在下面的注释中(var i=0,iLen=values.length;i
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);}