我正在处理一个查询谷歌表单,它收集参与者对某个问题的投票。我想根据 ID 号限制参与者。我在考虑三种方法:如果输入的 ID 不在给定列表中,则阻止提交表单。(我更喜欢这种方法,但到目前为止找不到任何有用的代码)使用Google 表单上的 GAS通过 onFormSubmit 触发器提交表单后,删除链接响应电子表格中的行。这是我的代码不起作用:function onFormSubmit(e) { // Grab the session data again so that we can match it to the user's choices.var response = [];var values = SpreadsheetApp.openById('1rT9tKAi6ZSvZzBaXNSPMJAt4RKnW- 9lqiE9zvZV').getDataRange().getValues();for (var i = 1; i < values.length; i++) { var indiv = values[I]; var Fname = indiv[0]; var Lname = indiv[1]; var ID1 = indiv[2]; var ID2 = indiv[3]; // For every selection in the response, find the matching ID1 and title // in the spreadsheet and add the session data to the response array. if (e.namedValues[ID1] == ID1) { response.push(indiv); } else { Browser.msgBox('Your ID number does not matches the list'); }}使用Google 表格上的 GAS通过 onChange 触发器提交表单后,删除链接响应电子表格中的行。这是我的最大努力:function onChange(e) { var refvalues = SpreadsheetApp.getActive().getSheetByName('members_sheet').getDataRange().getValues(); var sheet = SpreadsheetApp.getActive().getSheetByName('Form Responses 1'); var values = sheet.getDataRange().getValues(); var indiv = values[values.length]; var ID1 = indiv[2]; var flag = 0; for (var i = 1; i < refvalues.length; i++) { var refindiv = refvalues[i]; var refID1 = refindiv[2]; if (ID1 == refID1) { flag = 1; } } if (flag == 0) { sheet.deleteRow(values.length); } };我是 Javascript 编码的新手,所以任何帮助都将不胜感激。
2 回答

Helenr
TA贡献1780条经验 获得超4个赞
如果输入的 ID 不在给定列表中,则阻止提交表单
最简单的方法是合并文本验证,您甚至不需要为它编写代码
只是在构建/编辑
ID1
问题时选择Regular expression
,matches
并指定所有允许提交表单的 ID|
用作分隔符
更多信息

饮歌长啸
TA贡献1951条经验 获得超3个赞
如果您希望将所有 id 保留在电子表格中,请在代码的开头尝试此操作。
function onFormSubmit(e) {
const ss=SpreadsheetApp.openById('your id');
const idsh=ss.getSheetByName('id sheet');
const idrg=ss.getRange(2,1,idsh.getLastRow()-1,1);
const idA=idrg.getValues().map(function(r){return r[0];});
if (idA.indexOf(e.namedValues['ID1'])==-1) {
Browser.msgBox('Your ID number does not match the list');
return;
}
//rest of your code here
}
添加回答
举报
0/150
提交
取消