我已经制作了一个表格来捕获2个数据 1)电子邮件地址 2)用户想要订阅的组。
每个小组都有自己的电子表格。
当用户提交表单时,表单应捕获电子邮件地址,并将数据发送到用户订阅的相应电子表格。
这是我到目前为止所做的。我被卡住了..
function onFormSubmit() {
var form = FormApp.getActiveForm();
var formResponses = form.getResponses();
for (var i = 0; i < formResponses.length; i++) {
var formResponse = formResponses[i];
var itemResponses = formResponse.getItemResponses();
for (var j = 0; j < itemResponses.length; j++) {
var itemResponse = itemResponses[j];
// Checks if it is multiple choice option
if (itemResponse.getItem().getType() == FormApp.ItemType.MULTIPLE_CHOICE) {
// If user chooses group 1, open spreadsheet and store user's email in 1st column
if (itemResponse.getResponse() == "1") {
var ss = SpreadsheetApp.openById("id goes here");
var sheet = ss.getSheetByName("Group subscription email");
}
}
}
}
}
答案 0 :(得分:0)
你想要发生什么事?如何将表单中的选项与要写入的电子表格相匹配?
如果是这样,您可以对所有电子表格ID的对象进行硬编码,并将其与表单选项相匹配。
var objOfSpreadsheetIDs = {"1":"oicjo0948t09afoa", "2":"498hnxoiv7r6gahauvgi", "3":"uuiocvgofhgeoyuih"};
Logger.log("Check my object: " + objOfSpreadsheetIDs["3"])
因此,您的代码可能如下所示:
var objOfSpreadsheetIDs = {"1":"oicjo0948t09afoa", "2":"498hnxoiv7r6gahauvgi", "3":"uuiocvgofhgeoyuih"};
// If user chooses group 1, open spreadsheet and store user's email in 1st column
var whatGroupUserChoose = itemResponse.getResponse();
var whatSS_ID = objOfSpreadsheetIDs[whatGroupUserChoose];
var ss = SpreadsheetApp.openById(whatSS_ID);
var sheet = ss.getSheetByName("Group subscription email");