使用脚本在电子邮件中包含选项形式时将Google表单嵌入脚本中的Google脚本中 [英] Embed a google form in email with script the way google does it when option include form in email is used

查看:82
本文介绍了使用脚本在电子邮件中包含选项形式时将Google表单嵌入脚本中的Google脚本中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将表格发送给某些人,并且使用Google脚本来完成. 我尝试使用以下代码将表单嵌入电子邮件中: https://stackoverflow.com/a/23671529/4305236 :

I have to send a form to some people and I do it with a google script. I try to embed the form in the email with this code : https://stackoverflow.com/a/23671529/4305236:

var form = FormApp.create('New Form');
....
var url = form.getPublishedUrl();
var response = UrlFetchApp.fetch(url);
var htmlBody = HtmlService.createHtmlOutput(response).getContent();
    MailApp.sendEmail({
    to: email,
    subject: subject,
    htmlBody: htmlBody,
  });
...

但是,当直接从google表单界面发送表单时,它不会像google那样发送表单.

But it doesn't send the form the way google does it when the form is sent directly from the google forms interface.

通过脚本发送的电子邮件;

Email sent by script;

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

The goal (Email sent by google form directly):

该问题已经被问过

This question is already asked here but has no response.

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

Finally, the goal is to change the form every day, so it is not possible to use a template in an email previously sent.

在此先感谢您的帮助.

推荐答案

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

I am sending pre-filled google form to users (partly filled and to be completed by him).

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

It does not send the form in the body of the email. But, it has a link which has to be clicked by the person to fill the form (some fields). Some fields are already filled by me (the sender of the email).

这很简单.

创建表单

填写您要预先填写的表单值.点击获取预填充链接"

Fill the form values which you want to be pre-filled. Click "Get prefilled link"

复制创建的网址.

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

USe the URL and fill the values from the google sheet.

我附上了我使用的代码

//
//
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
}
//




这篇关于使用脚本在电子邮件中包含选项形式时将Google表单嵌入脚本中的Google脚本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆