使用getEditResponseUrl()获取当前提交的表单的Google表单编辑响应URL

时间:2015-06-30 17:00:29

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

所以我有这个函数在表单提交时触发,当它用表单编辑URL填充我的整个回复电子表格时,我还希望函数返回当前提交的表单的URL,以便它可以用于另一个发送带有URL的电子邮件的功能。目前resultUrls正在返回每个表单回复的网址。如何仅获取当前提交的URL?

function assignEditUrls() {
  var form = FormApp.openById(formURL);
    //enter form ID here

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Form Responses');

    //Change the sheet name as appropriate
  var data = sheet.getDataRange().getValues();
  //var urlCol = 12; // column number where URL's should be populated; A = 1, B = 2 etc
  var responses = form.getResponses();
  var timestamps = [], urls = [], resultUrls = [];

  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))]:'']);
  }
  sheet.getRange(2, urlCol, resultUrls.length).setValues(resultUrls);  

  return resultUrls;
};

0 个答案:

没有答案