I have a simple form with just a few fields. I need to load data from a spreadsheet and create the form responses. I need 10,000 responses with for example serial number 1-10,000 as the only entry. The remaining fields will be empty.
Asked
Active
Viewed 171 times
1 Answers
2
var myFormID = 'Put_Form_ID_Here';
var howManyToSubmit = 10;//How many form submissions
function makeResponses(id,howMany) {
var allQuestionItems,firstQuestion,frm,i,newAnswer,newRezpnz;
id = id?id:myFormID;//If an id was passed to the function - use it
if (!id) {return;};//If there is no id to get the Form - quit
frm = FormApp.openById(id);//Get a reference to the Form
allQuestionItems = frm.getItems();//Get all questions in the Form
firstQuestion = allQuestionItems[0];
for (i=1;i<howManyToSubmit;i+=1) {
newRezpnz = frm.createResponse();
//Logger.log('thisAnswer: ' + thisAnswer)
newAnswer = firstQuestion.asTextItem().createResponse(i.toString());
newRezpnz.withItemResponse( newAnswer );
newRezpnz.submit();//submit a new response
};
};

Rubén
- 34,714
- 9
- 70
- 166

Alan Wells
- 30,746
- 15
- 104
- 152
-
Thank you Sandy. This script is doing what I needed. Only problem is when it runs I receive an error after a dozen or more loops. The error is "Sorry, the form response could not be submitted." I tried putting in a utilities.sleep(200) in the loop to slow things down. I added a line to see how many responses there were and adjusted the for loop to pick up from where it ended. However this will take ma quite awhile to enter 10,000 responses. Any ideas? – Chuck Horst Jul 09 '16 at 20:30
-
Sorry, figured it out. I had another script running at the same time also accessing the form. Turned the script off and good to go. Thanks! – Chuck Horst Jul 09 '16 at 20:44