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

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

问题描述

我是L.A.的一名高中老师,试图使用Apps Script创建课程注册系统。我需要用于此注册的Google表单:

问题1)根据学生的当前回复更新新页面上后续选择题的可用选项选择。



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

问题1例子)
一名学生注册参加研讨会1的绑定,并进入新页面。脚本根据学生的第一选择编辑新页面上的可用选项,并从该新页面的可能选项列表中删除绑定,因此礼节是他们唯一的剩余选项。



问题2示例)
学生可以注册绑定或礼节,这两个回复最初都可以在Google表单中找到。 30名学生参加了这次调查,所有30名学员都登记参加了绑缚研讨会。 Apps脚本引用响应电子表格,意识到绑定研讨会已满,然后将其从Google窗体的可能选择列表中删除。学生31去注册,他们唯一的选择是礼仪。



如果我的问题已经被问及回答(相信我,我确实搜索了!我相信我们可以在没有太多困难的情况下实现你的第二个目标,并修改表单,基于目前的回应状态。

方法是


  1. 创建表单并将它与响应电子表格相关联
  2. 在该响应电子表格中,使用函数(例如updateForm)创建脚本

  3. 使用onFormSubmit活动,请参阅使用特定于容器的可安装触发器

  4. 分析updateForm函数中的响应并使用表单服务修改您的表单

例如

  function updateForm(e){
if(e.values [1] =='Yes'){
Logger.log('是');
var existingForm = FormApp.openById('1jYHXD0TBYoKoRUI1mhY4j .... yLWGE2vAm_Ux7Twk61c');
Logger.log(existingForm);
var item = existingForm.addMultipleChoiceItem();
item.setTitle('你喜欢猫还是狗?')
.setChoices([
item.createChoice('Cats'),
item.createChoice('Dogs' )
])
.showOtherOption(true);


说到在第一个问题中实现目标,它更微妙,因为表格不会中途提交。根据对多项选择问题的不同反应,有可能出现在不同的页面上,但您的用例可能适合这种方法,尽管它不是非常动态的。

可能使用html服务来创建完全动态的体验。

让我知道您是否需要更多信息。


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:

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

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

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.

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.

The approach is to

  1. Create the form and associate it with a response spreadsheet
  2. In that response spreadsheet, create a script with a function (updateForm for instance)
  3. Bind that function with the onFormSubmit event, see Using Container-Specific Installable Triggers.
  4. Analyse the response in the updateForm function and modify your form using the Form Service

For instance

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.

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天全站免登陆