2016-07-08 30 views

回答

1
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 
    }; 
}; 
+0

謝謝桑迪。這個腳本正在做我所需要的。唯一的問題是,它運行時,我收到了一打或更多循環後的錯誤。錯誤是「對不起,表單響應無法提交。」我嘗試在循環中放入utilities.sleep(200)來減慢速度。我添加了一行來查看有多少響應,並調整了for循環從結束的地方開始。然而,這需要很長時間才能輸入10,000個響應。有任何想法嗎? –

+0

對不起,算了一下。我有另一個腳本在同一時間運行也訪問表單。關閉劇本,好走了。謝謝! –