此 Google App 腳本代碼回傳表單的所有更新(答案),但我只想從表單的許多欄位中的選定欄位回傳。
例如,我只想回傳姓名、地址、手機。
有可能做到 GAS 嗎?
function getArrayOfLastSubmissionsAnswers() {
var allQuestions,i,itemType,L,thisAnswer,thisQuestion,thisSubmissionsAnswers,number_of_submissions;
//Define all variables without assigning a value - value at this point
//is undefined
number_of_submissions = FormApp.openById('1VH8ayeXPtsURs9MPxIJ9bj6wQVXmdD9yQ-JWHyOAZ8').getResponses().length;
allQuestions = FormApp.openById('1VH8ayeXPtysURs9PxIJ9bj6wQVXmdD9yQ-JWHyOAZ8').getResponses()[number_of_submissions - 1].getItemResponses();
L = allQuestions.length;//How many questions are there in the Form
thisSubmissionsAnswers = [];//Create an empty array for answers
for (i=0;i<L;i ) {//Loop through all the questions in this Form submission
thisQuestion = allQuestions[i];//Get this question
itemType = thisQuestion.getItem().getType();
if (itemType === FormApp.ItemType.PAGE_BREAK) {
continue;//keep looping
};
thisAnswer = thisQuestion.getResponse();//Get the answer
Logger.log(i " - " thisAnswer);
thisSubmissionsAnswers.push(thisAnswer);//add answer to the array
};
Logger.log("thisSubmissionsAnswers: " thisSubmissionsAnswers);
return thisSubmissionsAnswers;
};
uj5u.com熱心網友回復:
您可以使用方法getTitle()來檢索問題文本
樣本:
...
thisQuestion = allQuestions[i];
var questionTitle = thisQuestion.getItem().getTitle();
console.log("question: " questionTitle);
if(questionTitle == "Name" || questionTitle == "Address" || questionTitle == "Mobile"){
...
thisAnswer = thisQuestion.getResponse();//Get the answer
Logger.log(i " - " thisAnswer);
thisSubmissionsAnswers.push(thisAnswer);//add answer to the array
...
}
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/434960.html
上一篇:將資料寫入單列中的谷歌表格嘗試將資料寫入確定范圍之外的列
下一篇:將數值從網站匯入Google表格
