本文介绍了使用脚本创建表单:分页并转到页面问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我提问之前,我想指出我是法国人,所以我的英语可能很差.如果我的问题不明白,我会尽量用更好的方式解释.

Before I ask my question, I want to point out that I'm french, so I may have a bad english. If my problem is not understood, I'll try to explain it in better ways.

我目前正在使用谷歌脚本来创建表单.在这个表格中,我想问受访者几个选择题.为了得到好的和具体的结果,我想根据受访者的情况调整我提出的问题.

I am currently working on a google script to create a form. In this form I want to ask respondent several multiple choice question.In order to get good and specific results, I want to adapt the questions I ask to the profile of the respondent.

为了清楚起见,这是我的表格的形状:我首先向受访者提出第一个问题,其中有 5 个可能的答案.回答后,必须将受访者定向到新页面.在这个新页面上,有一个新的多项选择题,有 2 个可能的答案.同样,在回答时,响应者必须被引导到一个新页面等等......最后,当我得到我想要的所有细节时,我会向受访者提出精确的问题.最后一页是一个包含很多选择题的页面,所有受访者都必须回答这些问题,不取决于他们的个人资料.

To make it clear this is the shape of my form :I start by asking the respondent a first question with 5 possible answer. Upon the answer, the respondent will have to be directed to a new page.On this new page, there is a new multiple choice question with 2 possible answers. Again, upon the answer, the respondent has to be directed to a new page and so on...At the end, when I get all the details I want, I ask precise questions to the respondent.The final page is a page containing a lot of multiple choice question, which all respondent will have to answer, no depending of their profile.

我曾尝试以这种方式在 google 脚本上编写它:

I have tried to write it on google script this way :

var page1 = form.addPageBreakItem()
    .setTitle('First page');
var item = form.addMultipleChoiceItem();
 item.setTitle('Question')
     .setChoices([
         item.createChoice('Yes',page2),
         item.createChoice('No',page3)
       ]);
var page2 = form.addPageBreakItem()
    .setTitle('Second page');
var page3 = form.addPageBreakItem()
    .setTitle('Third page');

但是由于page2和page3是在page1之后定义的,脚本不理解,无法根据答案跳转到page3或page2.我曾尝试先定义我的所有页面,但后来我不知道如何将我的多选题添加到特定页面中.

But as page2 and page3 are defined after page1, the script does not understand it, and cannot jump to page3 or page2 upon the answer.I have tried to defined all my page first, but then I don't know how to add my multiple answer question into a specific page.

有人可以给我一个提示吗?无论如何,感谢您的阅读,如果不清楚,请随时寻求更多解释

Does anybody can give me a hint ?Thanks for reading anyway, and don't hesitate to ask for more explanations if it is not clear

推荐答案

你只需要改变你的操作顺序;您不需要将 item 上的操作放在一起.这是一个使用您的代码的示例:

You only need to change the order of your operations; you do not need to keep the operations on item together. Here's an example, using your code:

function createForm() {
  var title = 'Multipage Form Test';
  var description = 'Stackoverflow question 17083500';

  var form = FormApp.create(title)
      .setDescription(description)
      .setConfirmationMessage('Thanks for responding!');

  var page1 = form.addPageBreakItem()
      .setTitle('First page');
  var item = form.addMultipleChoiceItem();
  var page2 = form.addPageBreakItem()
      .setTitle('Second page');
  var page3 = form.addPageBreakItem()
      .setTitle('Third page');

  item.setTitle('Question')
      .setChoices([
         item.createChoice('Yes',page2),
         item.createChoice('No',page3)
       ]);

  Logger.log(form.getEditUrl());
  Logger.log(form.getPublishedUrl());
}

从日志中复制编辑 URL",然后检查 - 您会发现表单具有您正在寻找的行为:

Copy the "edit URL" from the Logs, and check - you'll find that the form has the behavior you are looking for:

这篇关于使用脚本创建表单:分页并转到页面问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 19:21
查看更多