如何从谷歌表单发送包含编辑网址的电子邮件?

时间:2017-05-11 00:19:55

标签: google-sheets

我已准备好将脚本添加到电子表格中的列,其标题为“编辑网址”。现在,如何向参与者发送电子邮件,该电子邮件在“编辑网址”列中具有值,作为邮件正文的一部分。

以下是获取修改网址并将其添加到电子表格的脚本:

/*
 * Global Variables
 */`enter code here`

// Form URL
var formURL = 'https://docs.google.com/forms/d/1dLhH9GVu9mLNy7JdikXGvNwSjgl-3GJDG98kxyDOxhM/viewform';
// Sheet name used as destination of the form responses
var sheetName = 'Form Responses 1';
/*
 * Name of the column to be used to hold the response edit URLs 
 * It should match exactly the header of the related column, 
 * otherwise it will do nothing.
 */
var columnName = 'Edit Url' ;
// Responses starting row
var startRow = 2;

function getEditResponseUrls(){
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
  var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues(); 
  var columnIndex = headers[0].indexOf(columnName);
  var data = sheet.getDataRange().getValues();
  var form = FormApp.openByUrl(formURL);
  for(var i = startRow-1; i < data.length; i++) {
    if(data[i][0] != '' && data[i][columnIndex] == '') {
      var timestamp = data[i][0];
      var formSubmitted = form.getResponses(timestamp);
      if(formSubmitted.length < 1) continue;
      var editResponseUrl = formSubmitted[0].getEditResponseUrl();
      sheet.getRange(i+1, columnIndex+1).setValue(editResponseUrl);
    }
  }
}

1 个答案:

答案 0 :(得分:0)

我通过电子邮件向用户发送编辑网址,并将此代码添加到表单

上的脚本中

//电子邮件编辑回复网址     var editURL = e.response.getEditResponseUrl();

MailApp.sendEmail(Email, subject,

“\ n \ n您可以在以下位置编辑您的回复:”+ editURL +  “\ n \ n您可以在http://google-form.com”+

提交新报告