Embed a google form in email with script the way google does it when option include form in email is used

前端 未结 2 1146
慢半拍i
慢半拍i 2021-02-14 06:43

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:

2条回答
  •  爱一瞬间的悲伤
    2021-02-14 07:10

    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).

    It is pretty straight forward.

    Create the form

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

    Copy the url created.

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

    I am enclosing the code I use

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

    "; message += "" +"" +"" +"" +"" +"" +"" +"" 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[m][0]+"" +"" +"" +"" +"" +"" +"" } else { //if appraisal done //if (emps[m][15]=="") {joined=""} else { joined=Utilities.formatDate( emps[m][15],"GMT+05:30", "dd-MM-YY")} ; message += "" +"" +"" +"" +"" +"" +"" }//if appraisal done //}//if to be appraised AND ACTIVE }//for each emp under the hod message+=""+ ""+ "
    "+""+" Emp No "+""+""+" Name "+""+""+" Desig "+""+""+" Dept "+""+"Link (Submit once only)"+""+"
    "+emps[m][1]+""+emps[m][3]+""+emps[m][11]+"click to evaluate
    "+emps[m][0]+""+emps[m][1]+""+emps[m][3]+""+emps[m][11]+"Appraisal Completed
    "+'
    .

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

提交回复
热议问题