【问题标题】:How can I create a waitlist when a Google Form submission limit is reached?当达到 Google 表单提交限制时,如何创建候补名单?
【发布时间】:2014-10-22 16:38:38
【问题描述】:

限制可以提交 Google 表单的人数,然后在达到限制后向其他人提供加入等候名单的选项的最佳方法是什么?

当达到定义的限制时,我可以使用以下脚本关闭表单,但我想在此时打开不同的表单以收集候补名单提交。

function closeForm() {
    // get active form
    var form = FormApp.getActiveForm();

    // retrieve number of responses thusfar
    var responses = form.getResponses();

    // set close message
    var msg = "We're sorry, but this session is full. Future sessions will be announced in the CISL Daily Bulletin. Thank you for your interest.";

    // do the math
    if(responses.length >= 1) {
        form.setAcceptingResponses(false).setCustomClosedFormMessage(msg);
    }
}

我查看了 Google 文档帮助论坛并在此处进行了搜索。到目前为止,我所发现的很少是基于旧版本的 Google 表单。

关于如何做到这一点的任何建议?

【问题讨论】:

    标签: google-apps-script registration


    【解决方案1】:

    不确定最好的方法是什么,但我想到了一个可以按预期工作的解决方案,但是 - 这是一个严重的警告 - 有点曲折...

    无论如何,如果您的表单不是太复杂,它可能很容易设置。下面的示例适用于只有文本字段的表单,因此代码非常简单。如果您使用不同的问题类型,则必须为您使用的每种类型添加一个条件,并相应地调整 addElement。

    全球的想法是制作一个备份表单来保存所有现有字段,删除所有字段并为等待列表创建一个“给出你的名字”字段。

    然后restore 函数可以轻松地重新构建表单。

    表单公共 url 将始终相同,并且可以无限期地重复使用表单...这是该脚本的主要(唯一)优点。

    也许有人会提出更智能和/或更简单的解决方案,我很乐意从中学习。

    编辑:我添加了一个 onFormSubmit 触发器创建函数,并稍微更改了一些逻辑以最适合正常的工作流程:当响应数量为

    function createTrigger(){
      var form = FormApp.getActiveForm();
      ScriptApp.newTrigger('checkFormForLimit').forForm(form).onFormSubmit().create();
    }
    
    function checkFormForLimit() {
      var form = FormApp.getActiveForm();
      var responses = form.getResponses();
      Logger.log(responses.length);
      if(responses.length<5) {return};// do nothing if not over the limit
      if(DriveApp.getFilesByName('backup'+form.getTitle()).hasNext()){ // check if bkp already exists
        var formBkp = FormApp.openById(DriveApp.getFilesByName('backup'+form.getTitle()).next().getId());// if it does, open it
      }else{
        var formBkp = FormApp.create('backup'+form.getTitle());// else create it
      }
      var msg = "We're sorry, but this session is full. Future sessions will be announced in the CISL Daily Bulletin. Thank you for your interest.";
      formBkp.setDescription(form.getDescription());
      form.setDescription(msg);
      var items = form.getItems();
      for(var n in items){
        var item = items[n];
        if(item.getType()==FormApp.ItemType.TEXT){
          formBkp.addTextItem().setTitle(item.getTitle());
          form.deleteItem(item);
        }
      }
      form.addTextItem().setTitle('Type your name to subscribe to the wait list')
    }
    
    function restoreForm(){
      var form = FormApp.getActiveForm();
      form.deleteItem(form.getItems()[0]);
      var formBkp = FormApp.openById(DriveApp.getFilesByName('backup'+form.getTitle()).next().getId());
      form.setDescription(formBkp.getDescription());
      var items = formBkp.getItems();
      for(var n in items){
        var item = items[n];
        if(item.getType()==FormApp.ItemType.TEXT){
          form.addTextItem().setTitle(item.getTitle());
          formBkp.deleteItem(item);
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-10
      • 2015-10-18
      相关资源
      最近更新 更多