使用goToPage添加多项选择问题

时间:2016-02-10 00:37:52

标签: google-apps-script

我正在尝试使用goToPage设置添加多项选择题。我已经遵循了文档,我无法弄清楚我是否发现了错误或做错了什么。

我在这一行收到错误,我不知道原因: var choice1 = ques.createChoice(name1, page1Item); //Error: InternalError: Cannot find method createChoice(string,Item).

function testCreateChoice(){
  // documentation: https://developers.google.com/apps-script/reference/forms/multiple-choice-item#createchoicevalue-navigationitem

  // define variables
  var mcId = 1310873270;  //Id of multiple choice queston
  var pageId1 = 1255540175; //Id of page 2
  var pageId2 = 1103976777; //Id of page 3
  var name1 = "Go To Page 2";
  var name2 = "Go To Page 3";

  // open question and itmes
  var form = FormApp.openByUrl(SpreadsheetApp.getActiveSpreadsheet().getFormUrl());
  var ques = form.getItemById(mcId).asMultipleChoiceItem();
  var page1Item = form.getItemById(pageId1);
  var page2Item = form.getItemById(pageId2);

  //verify
  Logger.log(ques.getTitle());  // correctly itentified
  Logger.log(page1Item.getTitle()); // correctly itentified
  Logger.log(page2Item.getTitle()); // correctly itentified

  //add Choices  ~ This is where I get the error
  var choice1 = ques.createChoice(name1, page1Item);  //Error:  InternalError: Cannot find method createChoice(string,Item).
  var choice2 = ques.createChoice(name2, page2Item);  //Error:  InternalError: Cannot find method createChoice(string,Item).
  var newChoices =[choice1,choice2];
  ques.setChoices(newChoices);
}

1 个答案:

答案 0 :(得分:1)

好笑,我发现了另一篇帖子,我帮助某人回答了类似的问题。写完这么多代码后,你会忘记自己的答案。

解决方案是将.asPageBreakItem();添加到page1Item和page1Item的get项的末尾。

  var page1Item = form.getItemById(pageId1).asPageBreakItem();
  var page2Item = form.getItemById(pageId2).asPageBreakItem();