【问题标题】:Using Google apps script apply "go to sections based on answer" on Google Form ERROR Message : list.createChoice is not a function使用 Google 应用程序脚本在 Google 表单错误消息上应用“根据答案转到部分”:list.createChoice 不是函数
【发布时间】:2022-08-02 18:09:37
【问题描述】:

我正在使用 FORM RANGER 自动填充数据,但一旦填充,多项选择转到基于答案的部分总是擦除。 我正在尝试使用 GAS 在此 FORM 打开时保持分支,但错误消息“list.createChoice 不是函数”。 我之前读过类似的问题并处理了这个问题大约 2 天,但仍然无法弄清楚...... 以下是我的代码,希望有人能帮助我,谢谢!

    function GoToPage() {
        var form = FormApp.openById(\'\');

        var list = form.getItems(FormApp.ItemType.MULTIPLE_CHOICE);
        var list1 = form.getItems(FormApp.ItemType.MULTIPLE_CHOICE)[0].asMultipleChoiceItem().getChoices().map(choice => choice.getValue());
        var choice1 = list1[0];
        var choice2 = list1[1];
        var choice3 = list1[2];

        var pagelist = form.getItems(FormApp.ItemType.PAGE_BREAK);
        var pagebreak01 = pagelist[2].asPageBreakItem();
        var pagebreak02 = pagelist[3].asPageBreakItem();
        var pagebreak03 = pagelist[4].asPageBreakItem();

        var choices = [];
        choices.push(list1.createChoice(choice1,pagebreak01));
        choices.push(list1.createChoice(choice2,pagebreak02));
choices.push(list1.createChoice(choice3,pagebreak03));
        list.setChoices(choices);
    }

添加: 我有四个多项选择,由电子表格中的 FORM RANGER 自动填充,并设置四个选项一一转到四个部分。

一旦我执行,它显示: 「TypeError: list1.createChoice 不是函数 转到页面 @GOTOSEC.gs:16”

我认为这个错误可能是因为输入变量不适合 \"createChoice\" 函数,但我阅读了很多以前的帖子并尝试了很多次其他语法,仍然无法工作:(

  • 欢迎来到Stack Overflow。请添加文本错误消息。
  • 错误信息是\"「TypeError: list1.createChoice is not a function GoToPage @ GOTOSEC.gs:16」\",谢谢!

标签: google-apps-script google-forms


【解决方案1】:

问题是第三行,

var list = form.getItems(FormApp.ItemType.MULTIPLE_CHOICE);

返回一个数组。假设您要修改第一个多项选择题,请将这一行替换为

var list = form.getItems(FormApp.ItemType.MULTIPLE_CHOICE)[0];

【讨论】:

  • 感谢您的帮助,我已经尝试过这种方式,也尝试将 "list1.createChoice" 更改为 "list.createChoice" ,但仍然显示相同的消息。
【解决方案2】:

最后,我用 Rubén 的解决方案解决了这个问题,并替换了这种语法:

choices.push(list1.createChoice(choice,pagebreak));

对此:

choices.push(list.asMultipleChoiceItem().createChoice(list1[i], pagebreak));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-28
    • 2020-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-26
    • 1970-01-01
    相关资源
    最近更新 更多