删除存储在Google表单回复中的电子邮件

时间:2018-09-22 10:08:47

标签: google-apps-script google-apps google-form

背景:

我正在尝试创建一个将由人们填写的Google表单,然后发送另一个由其他人(夫妇)填写的表单。表单响应需要匿名,但是响应也需要链接。

到目前为止,我的解决方案-使用唯一的ID进行链接(荣誉-> How to assign a unique ID to a google form input?),然后使用输入的电子邮件发送带有预制链接的消息,该消息具有指向该ID的下一个表格的预制链接,然后删除工作表中的电子邮件地址。

问题

我要坚持的下一个卫生条件-删除Google表单回复中的电子邮件地址。一种方法是使用deleteAllResponses(),但这也会删除我打算使用的Google预先进行的基本数据分析(以节省创建某些图形的时间)。

我试图找到一种方法来访问响应对象并删除/修改电子邮件字段,但无法实现。

非常感谢您的帮助。

function myFunction() {
  //delete the last email that was added
  function deleteEmails(Row){
    sheet.getRange('B'+Row + ':B'+Row).clearContent();
  }

  //delete all responses - would like to change this to only delete/modify the email field.
  function deleteResponses() {
    var form = FormApp.openById('The form ID');
    form.deleteAllResponses();
  }

  //get the data on the sheet
  var sheet = SpreadsheetApp.openById("The sheet ID").getSheetByName('Form Responses 1');
  var StartRow = 1;
  var LastRow = sheet.getLastRow();
  var Range = sheet.getRange(LastRow, 2, 1, 62)
  var AllValues = Range.getValues();

  //if the person disagrees to fill the form - dont send an email
  if (AllValues[0][1] != 'disagree') {
    var SendTo = AllValues[0][0];
    var body = "Thank you for answering pfa a link for the sedond form";

    //send the actual email  
    MailApp.sendEmail({
        to: SendTo,
        cc: "",
        subject: 'Thank you for answering',
        htmlBody: body,
    }); 
  }

  //delete emails and responses
  deleteEmails(LastRow)
  deleteResponses()
}

0 个答案:

没有答案