How to generate a pre-filled form URL for Google Form

后端 未结 3 766
慢半拍i
慢半拍i 2020-12-14 05:20

I\'m looking for a programmatic way to automate the generation of pre-filled URLs for google forms.

In a recent update, Google introduced a new Forms product to Goog

相关标签:
3条回答
  • 2020-12-14 05:35

    I required something similar for users to go and edit their response, take a look here: http://productforums.google.com/forum/#!topic/docs/LSKKCR3VHC8

    Copy / paste code below:

    function assignEditUrls() {
    var form = FormApp.openById('1MonO-uooYhARHsr0xxxxxxxxxxxxxxxxxxxxx');
    //enter form ID here
    
      var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Form Responses');
    
        //Change the sheet name as appropriate
      var data = sheet.getDataRange().getValues();
      var urlCol = 4; // 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);  
    }
    
    0 讨论(0)
  • 2020-12-14 05:48

    This is not possible right now but this request is being tracked on the Issue Tracker here. Please add your use cases there and watch it for updates.

    0 讨论(0)
  • 2020-12-14 05:52

    I found no way to create a pre-filled URL from the form id itself. It is possible if the form has already an answer:

      var form = FormApp.openById('1nGvvEzQHN1n-----_your_for_id_----zemoiYQA');
      var responses = form.getResponses();
      Logger.log(responses[0].toPrefilledUrl());
    
    0 讨论(0)
提交回复
热议问题