使用 Apps 脚本动态编辑实时 Google 表单中的多项选择选项 [英] Dynamically edit multiple choice options in live Google Form using Apps Script

查看:21
本文介绍了使用 Apps 脚本动态编辑实时 Google 表单中的多项选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是洛杉矶的一名高中教师,正在尝试使用 Apps 脚本创建课程注册系统.我需要用于此注册的 Google 表单:

I'm a high school teacher in L.A. trying to create a course registration system using Apps Script. I need the Google Form I'm using for this registration to:

问题 1) 根据学生当前的回答选择,更新新页面上后续多项选择题中的可用选项.

Question 1) Update the choices available in subsequent multiple choice questions on new pages based on a student's current response choices.

问题 2) 当多项选择达到上限"时,从表单中删除选项.

Question 2) Eliminate choices from the form when a multiple choice option has reached it's "cap".

问题 1 示例)一名学生在研讨会 1 中注册了领带",并进入了一个新页面.脚本会根据学生的第一选择编辑该新页面上的可用选项,并从该新页面上的可能选项列表中删除绑定",因此礼节"是他们唯一剩下的选项.

Question 1 Example) A student registers for "tie-tying" in workshop 1, and gets taken to a new page. The Script edits the available choices on that new page based on the student’s first choice, and removes "tie-tying" from the list of possible choices on that new page, so "etiquette" is their only remaining option.

问题 2 示例)学生可以注册领带"或礼仪",这两种回答最初都可以在 Google 表格中找到.30 名学生参加了调查,所有 30 名学生都注册了绑扎"工作坊.Apps 脚本引用响应电子表格,意识到捆绑"研讨会已满,然后将其从 Google 表单的可能选项列表中删除.31学生去报名,唯一的选择就是礼仪".

Question 2 Example) Students can either register for "tie-tying" or "etiquette", both responses are initially available in the Google Form. 30 students take the survey, all 30 register for the "tie-tying" workshop. The Apps Script references the response spreadsheet, realizes the "tie-tying" workshop is full, then removes it from the Google Form's list of possible choices. Student 31 goes to register, and their only option is "etiquette".

如果我的问题已经有人提出并得到解答(相信我,我确实搜索过!)我会很感激重定向.

If my question has already been asked and answered (believe me, I did search!) I'd appreciate the redirection.

推荐答案

我相信我们可以毫不费力地实现您的第二个目标,并根据当前的响应状态修改表单.

I believe we can achieve your second objective without too much difficulty and modify the form, based on the current state of response.

方法是

  1. 创建表单并将其与回复电子表格相关联
  2. 在该响应电子表格中,创建一个带有函数的脚本(例如 updateForm)
  3. 将该函数与 onFormSubmit 事件绑定,请参阅使用特定于容器的可安装触发器.
  4. 分析 updateForm 函数中的响应并使用表单服务修改您的表单

例如

function updateForm(e) {
  if (e.values[1] == 'Yes') {
    Logger.log('Yes');
    var existingForm = FormApp.openById('1jYHXD0TBYoKoRUI1mhY4j....yLWGE2vAm_Ux7Twk61c');
    Logger.log(existingForm);
    var item = existingForm.addMultipleChoiceItem();
     item.setTitle('Do you prefer cats or dogs?')
     .setChoices([
         item.createChoice('Cats'),
         item.createChoice('Dogs')
      ])
     .showOtherOption(true);
  }
}

说到实现你第一个问题中的目标,它更微妙,因为表单不会中途提交.可以根据对多项选择题的不同回答访问不同的页面,您的用例可能适合这种方法,尽管它不是很动态.

When it comes to achieving the goal in your first question, its more delicate, as the form will not submit mid way. What is possible is to go to different pages based on different responses to a Multiple Choice question, your use case may fit this method, although its not very dynamic.

进一步可以使用 html 服务来创建完全动态的体验.

Further its possible to use html Service to create completely dynamic experience.

如果您需要更多信息,请告诉我.

Let me know if you need further information.

这篇关于使用 Apps 脚本动态编辑实时 Google 表单中的多项选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆