当使用选项包含电子邮件中的表单时,谷歌会以谷歌的方式在电子邮件中嵌入谷歌表格

时间:2018-06-13 10:07:16

标签: google-apps-script google-form

我必须向某些人发送表单,然后使用Google脚本执行此操作。 我尝试使用以下代码将表单嵌入到电子邮件中:https://stackoverflow.com/a/23671529/4305236

eventAfterAllRender: function(view)
{
  $('.fc-bgevent').hover(function() {
    console.log('ok');
  });
}

但是,当Google直接从Google表单界面发送表单时,它不会像谷歌那样发送表单。

脚本发送的电子邮件;

目标(直接通过Google表单发送的电子邮件):

此问题已被问及here,但没有回应。

最后,目标是每天更改表单,因此无法在之前发送的电子邮件中使用模板。

提前感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

当Google直接将表单发送给人们并将表单嵌入到电子邮件中时,他们将使用他们的新产品AMP。您可以在此处了解更多信息:

您使用的代码获取表单的原始HTML,就像在浏览器中为用户呈现的那样。该代码不是AMP格式。因此,它不会做您想要的事情。

如果您希望获得AMP的经验,则需要自己创建AMP电子邮件。

我不认为FormApp像向https://docs.google.com/forms/那样可以通过编程方式将表单发送给其他人。

我希望能帮上忙。

答案 1 :(得分:0)

我正在向用户发送预先填写的Google表单(部分填写并由他完成)。

它不会在电子邮件正文中发送表格。但是,它具有一个链接,该链接必须由用户单击以填写表格(某些字段)。我(电子邮件的发件人)已经填写了一些字段。

这很简单。

创建表单

填写您要预先填写的表单值。点击“获取预填充链接”

复制创建的网址。

使用URL并填写Google工作表中的值。

我附上了我使用的代码

//
//
function appraisal_mail_to_all(){
  //https://docs.google.com/forms/d/e/..../viewform?usp=pp_url&entry.1559436995=name&entry.226490833=Satisfactory&entry.1002429742=comment1&entry.1373188131=Poor&entry.2023543437=comment2&entry.332797694=Indifferent&entry.928578055=comment3&entry.1637933262=Poor&entry.1733301737=comment4&entry.1465918066=job_descrip&entry.31857466=1234&entry.370551729=dept&entry.835006919=qualification&entry.914497805=joined&entry.976738938=hod
  var ss = SpreadsheetApp.getActiveSpreadsheet();  
  var activesheet=SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName();
  if (activesheet!=="Emp") {Browser.msgBox('Pl. click this option from "Emp" sheet');return;};   
  var response = Browser.msgBox('Mail Will go to all HOD.', "Are you sure ?" , Browser.Buttons.YES_NO);
  if (response == "yes") {} else {return};
  var empsht = ss.getSheetByName("Emp");  
  var emplr=empsht.getLastRow();
  var empdvals = empsht.getRange("A2:W"+emplr).getValues();//all
  var empcvals=ArrayLib.filterByText(empdvals, 18, "Yes");//active
  var empavals=ArrayLib.filterByText(empcvals, 21, "TRUE" );//appraised
  var hods = ArrayLib.unique(empavals, 16);//uniq
  var joined="";
  //var appss=SpreadsheetApp.openById("....");//appraisal
  //var appsht=appss.getSheetByName("Form Responses 1")  
  //var appvals = appsht.getDataRange().getValues();
  for (k=0;k<hods.length;k++){ 
      var link1="",link2="",link3="",link4="";
      var message = "Dear "+hods[k]+",<br><br>Pl. click the link to fill the performance appraisal of the people reporting to you (if pending). Pl. submit it only once per employee within two days. Once submitted, it can not be changed. Next year increment, promotion etc will be based on the appraisal. Your kind co-operation is requested.<br><br>";
      message += "<table cellspacing='2' cellpadding='2' dir='ltr' border='1' style='font-size:10pt;font-family:arial,sans,sans-serif;border-collapse:collapse;border:1px solid #ccc;font-weight:normal;color:black;background-color:white;text-align:center;text-decoration:none;font-style:normal'"
      +"<tr>"
      +"<td bgcolor = '#ffffff', Align = 'center'>"+"<b>"+" Emp No "+"</td>"
      +"<td bgcolor = '#ffffff', Align = 'center'>"+"<b>"+" Name "+"</td>"
      +"<td bgcolor = '#ffffff', Align = 'center'>"+"<b>"+" Desig "+"</td>"
      +"<td bgcolor = '#ffffff', Align = 'center'>"+"<b>"+" Dept "+"</td>"
      +"<td bgcolor = '#ffffff', Align = 'center'>"+"<b>Link (Submit once only)"+"</b>"+"</td>"
      +"</tr>"
      +"<tr>"
      var emps=ArrayLib.filterByText(empavals, 16, hods[k]);
      var hod=ArrayLib.filterByText(empdvals,1, hods[k]);
      //Browser.msgBox(hod);
      //if (hod.length > 1) {Browser.msgBox(hod[0][1] + " is appearing more than once in emp master. Pl. correct it");return};
      for (m=0;m<emps.length; m++){
        //if (emps[m][21]==true && emps[m][18]=="Yes") {//to be appraised and active
        if (emps[m][22]=="") {//appraisal not done
          //if ( ArrayLib.find(appvals, 12, emps[m][0]) == 0 ) { //emp no not found in appraisal data
          //if (appdone.length == 0) {//appraisal not done
          //if (emps[m][15]=="") {joined=""} else { joined=Utilities.formatDate( emps[m][15],"GMT+05:30", "dd-MM-YY")} ;
          link4= 'https://docs.google.com/forms/d/e/..../viewform?usp=pp_url&entry.1559436995='+emps[m][1] +'&entry.31857466='+emps[m][0]+'&entry.370551729='+emps[m][11] + '&entry.914497805='+ joined +'&entry.976738938='+emps[m][16] ; 
          link3 = link4.replace(/#/g, "");
          link2 = link3.replace(/,/g, "");
          link1 = link2.replace(/ /g, "%20");
          message += "<td bgcolor = '#ffffff', Align = 'center'>"+emps[m][0]+"</td>"
          +"<td bgcolor = '#ffffff', Align = 'center'>"+emps[m][1]+"</td>"
          +"<td bgcolor = '#ffffff', Align = 'center'>"+emps[m][3]+"</td>"
          +"<td bgcolor = '#ffffff', Align = 'center'>"+emps[m][11]+"</td>"
          +"<td bgcolor = '#ffffff', Align = 'center'><a href='" +link1+ "'>click to evaluate</a></td>"
          +"</tr>"
          +"<tr>"
          } else { //if appraisal done
          //if (emps[m][15]=="") {joined=""} else { joined=Utilities.formatDate( emps[m][15],"GMT+05:30", "dd-MM-YY")} ;
          message += "<td bgcolor = '#ffffff', Align = 'center'>"+emps[m][0]+"</td>"
          +"<td bgcolor = '#ffffff', Align = 'center'>"+emps[m][1]+"</td>"
          +"<td bgcolor = '#ffffff', Align = 'center'>"+emps[m][3]+"</td>"
          +"<td bgcolor = '#ffffff', Align = 'center'>"+emps[m][11]+"</td>"
          +"<td bgcolor = '#ffffff', Align = 'center'>Appraisal Completed</td>"
          +"</tr>"
          +"<tr>"
        }//if appraisal done
      //}//if to be appraised AND ACTIVE
      }//for each emp under the hod
      message+="</tr>"+  "</tr>"+ "</table>"+'<br>.<br><br>';
      var subject1="Performance Evaluation of people under you (Confidential)";
      if  (hod[0][7]=="") { var hodm="..."} else {var hodm=hod[0][7]};
      //var hodm="";
      MailApp.sendEmail({        to: hodm,        subject: subject1,        htmlBody: message      });
      //Browser.msgBox(hodm+subject1+message)
  }//for each hod
}
//