如何使用Google Apps Script为Google Forms多选题提交多个响应
解决方案
Google Forms的多选类问题提交多个选项时,不能将选项拼接为字符串传入,直接将对应entry ID的取值修改为存储多个选项的数组即可。
代码示例
const obj = { "entry.1111": tName, "entry.2222": sFirst, "entry.3333": sLast, "entry.4444": ['Option 1', 'Option 2'], // 多选问题直接传入选项数组 "entry.5555": 'yes', "entry.6666": 'yes', "entry.7777": 'minor', "entry.8888": 'initial' } const options = { 'method': 'post', 'payload': obj } UrlFetchApp.fetch(url,options)
注意事项
- 传入的选项文本必须和Google Form中对应选项的原文完全一致,大小写、空格、特殊符号都不能有出入,否则会提交失败
- 如果多选值存储在Google Sheet的单元格中,且以逗号等符号分隔,可通过
split方法先转为数组,示例:"entry.4444": 单元格取值.split(',').map(item => item.trim()),去除每个选项前后的空格避免匹配错误 - 无需调整请求的其他配置,Google App Script的
UrlFetchApp会自动将数组类型的payload字段转换为表单可识别的重复参数格式
内容的提问来源于stack exchange,提问作者Andrew Valenzuela
相关产品推荐
相关产品推荐

