How to add “Edit Response” link to Google Forms emails?

前端 未结 9 1725
有刺的猬
有刺的猬 2020-12-05 02:46

I have a simple Google Form that collects data, and, using AppScript, sends confirmation emails to users who fill it out. After user submits the form, on confirmation, s/he

相关标签:
9条回答
  • 2020-12-05 03:36

    you can try to populate a form with the values given from that email address than delete previous answers ...

    it's not a beautiful way but it can works ...

    0 讨论(0)
  • 2020-12-05 03:37

    Does this help - I haven't tried it but I was looking for the same thing a while ago and noticed this.

    From this page https://developers.google.com/apps-script/reference/forms/

    code from there contains this:

    Logger.log('Published URL: ' + form.getPublishedUrl());
    Logger.log('Editor URL: ' + form.getEditUrl());
    

    Jon

    0 讨论(0)
  • 2020-12-05 03:37

    Try This: (Credits is not for me, because i merge two solutions of the third part)

    Source: Send Confirmation Email with Google Forms

    /* Send Confirmation Email with Google Forms */
    
    function Initialize() {
    
        var triggers = ScriptApp.getScriptTriggers();
    
        for (var i in triggers) {
            ScriptApp.deleteTrigger(triggers[i]);
        }
    
        ScriptApp.newTrigger("SendConfirmationMail")
            .forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
            .onFormSubmit()
            .create();
    
    }
    
    function SendConfirmationMail(e) {
      var form = FormApp.openById('***YOUR FORM CODE***');
        //enter form ID here
    
      var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('***SHEET NAME***');
    
        //Change the sheet name as appropriate
      var data = sheet.getDataRange().getValues();
      var urlCol = ***************COLUMN SEQUENCE EX 14******; // column number where URL's should be populated; A = 1, B = 2 etc
      var responses = form.getResponses();
      var timestamps = [], urls = [], resultUrls = [], url;
    
      for (var i = 0; i < responses.length; i++) {
        timestamps.push(responses[i].getTimestamp().setMilliseconds(0));
        urls.push(responses[i].getEditResponseUrl());
      }
      for (var j = 1; j < data.length; j++) {
    
        resultUrls.push([data[j][0]?urls[timestamps.indexOf(data[j][0].setMilliseconds(0))]:'']);
        url = resultUrls[i-1]
      }
      sheet.getRange(2, urlCol, resultUrls.length).setValues(resultUrls);  
    
        try {
    
            var ss, cc, sendername, subject, headers;
            var message, value, textbody, sender;
    
            // This is your email address and you will be in the CC
            cc = Session.getActiveUser().getEmail();
    
            // This will show up as the sender's name
            sendername = "****YOUR NAME******";
    
            // Optional but change the following variable
            // to have a custom subject for Google Docs emails
            subject = "Registro de Oportunidade submetido com sucesso";
    
            // This is the body of the auto-reply
            message = "Nós recebemos seu registro de oportunidade.<br>Muito Obrigado!<br><br>";
    
            ss = SpreadsheetApp.getActiveSheet();
            headers = ss.getRange(1, 1, 1, ss.getLastColumn()).getValues()[0];
    
            // This is the submitter's email address
            sender = e.namedValues["********COLUMN NAME OF DESTINATION E-MAIL************"].toString();
    
            for (var i in headers) {
    
                value = e.namedValues[headers[i]].toString();
    
                // Do not send the timestamp and blank fields            
                if ((i !== "0") && (value !== "")) {
                    message += headers[i] + ' :: ' + value + "<br>";
                }
            }
    
            message += "<br>Link to edit" + ' :: ' + url + "<br>";
            textbody = message.replace("<br>", "\n");
    
            GmailApp.sendEmail(sender, subject, textbody, 
                                {cc: cc, name: sendername, htmlBody: message});
    
        } catch (e) {
            Logger.log(e.toString());
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题