Created
June 17, 2021 17:37
-
-
Save thel3l/e3b1339ea7d18418eb742274c19a50dd to your computer and use it in GitHub Desktop.
Short Google Apps Script that takes data from a Google Sheet and posts it to a Google Form. Script autofilling forms etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myFunction() { | |
var Workbook = SpreadsheetApp.getActiveSpreadsheet(); | |
var Wrksheet = Workbook.getSheetByName("Sheet1"); // Enter sheet number | |
var FormURL = ""; // Enter Google form URL here | |
var FormData = ""; // init | |
// Replace w. your vars | |
var Name = ""; | |
var Age = ""; | |
var Mobile = ""; | |
var Fulladdress = ""; | |
// Number of rows to run | |
var numberofrows = 5; | |
for (i=2;i<=numberofrows;i++){ | |
console.log(i); //debug | |
Name = Wrksheet.getRange(i, 1).getDisplayValue(); | |
Age = Wrksheet.getRange(i, 2).getDisplayValue(); | |
Mobile = Wrksheet.getRange(i, 3).getDisplayValue(); | |
Fulladdress = Wrksheet.getRange(i, 4).getDisplayValue(); | |
// Replace w. your form url. | |
FormURL = "https://docs.google.com/forms/d/e/ABCD/formResponse?&pageHistory=0" | |
// Feeling lazy? Get this from the 'Get prefilled form' link on Forms | |
// Edit to the values in the target form | |
FormData = "&entry.350886759=" + Name + "&entry.363227935=" + Age + "&entry.263903406=" + Mobile + "&entry.1764822032=" + Fulladdress | |
finalURL = FormURL + FormData; | |
var options = { | |
"method" : "post" | |
}; | |
UrlFetchApp.fetch(finalURL,options); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment