You can create a pre-populated form URL from the form editor, as described in the documentation for Disk Forms . You will end up with a URL, for example:
https://docs.google.com/forms/d/--form-id--/viewform?entry.726721210=Mike+Jones&entry.787184751=1975-05-09&entry.1381372492&entry.960923899
buildUrls ()
In this example, question 1 “Name” has the identifier 726721210 , and question 2 - “Birthday” - 787184751 . Questions 3 and 4 are empty.
You can create a pre-populated URL by adapting the one provided through the user interface to be a template, for example:
function buildUrls() { var template = "https://docs.google.com/forms/d/--form-id--/viewform?entry.726721210=##Name##&entry.787184751=##Birthday##&entry.1381372492&entry.960923899"; var ss = SpreadsheetApp.getActive().getSheetByName("Sheet1");
This is quite effective - you can email a pre-filled URL to each person and they will already have questions.
betterBuildUrls ()
Instead of creating our template using brute force, we can combine it together programmatically. This will have the advantage that we can reuse the code without thinking about changing the template.
Each question in the form is an element. For this example, suppose a form has only 4 questions, as you described them. Element [0] - "Name", [1] - "Birthday", etc.
We can create a form response that we will not send - instead, we will partially fill out the form, only to get the pre-filled form URL. Since the Forms API understands the data types of each element, we can avoid manipulating the string format of dates and other types, which simplifies our code somewhat.
(EDIT: Is there a more general version of this in the checkboxes of a Google form on a form? )
function betterBuildUrls() { var ss = SpreadsheetApp.getActive(); var sheet = ss.getSheetByName("Sheet1"); var data = ss.getDataRange().getValues();
yymmdd function
Any date element in the pre-filled form URL is expected to be in this format: yyyy-mm-dd . This helper function extends the Date object with a new transformation processing method.
When reading dates from a spreadsheet, you will get a Date javascript object if the data format is recognized as a date. (Your example is not recognized, so instead of May 9th 1975 you can use 5/9/1975 .)