我是非常新的谷歌应用程序脚本,因为谷歌表单不能做条件所需的功能,我将需要修改自己的表单。我在谷歌应用程序脚本网站上找到了这段代码,我试着试着测试一下我是否能实现我想要的东西。我想要实现什么:
我从我的代码中得到了什么:
代码如下:
function myfunction(){
var form = FormApp.create('New Form');
var item = form.addCheckboxItem();
item.setTitle('What condiments would you like on your hot dog?');
item.setChoices([
item.createChoice('Ketchup'),
item.createChoice('Mustard'),
item.createChoice('Relish')
]);
var a= form.addMultipleChoiceItem()
.setTitle('Do you prefer cats or dogs?')
.setChoiceValues(['Cats','Dogs'])
.showOtherOption(true);
form.addPageBreakItem()
.setTitle('Getting to know you');
form.addDateItem()
.setTitle('When were you born?');
var b= form.addGridItem()
.setTitle('Rate your interests')
.setRows(['Cars', 'Computers', 'Celebrities'])
.setColumns(['Boring', 'So-so', 'Interesting']);
if (a != null){
b= b.setRequired(true);
}
Logger.log('Published URL: ' + form.getPublishedUrl());
Logger.log('Editor URL: ' + form.getEditUrl());
}
发布于 2018-05-30 15:44:58
关于您的if语句:变量" A“不会为空,因为您刚刚为变量A设置了一个值。
你必须记住你正在创建一个表单,把它看作是一次性的过程。当用户将其响应提交给您的表单时,此脚本将不会运行。
我可以在这里看到您试图实现的目标,遗憾的是,使用上面的代码是不可能的。
我可能会建议将你更喜欢猫还是狗作为必填问题,然后根据答案转到不同的部分。
例如,我喜欢猫,请到表格的第二部分。我喜欢狗,请到表格的第三部分。(如图所示。)
https://stackoverflow.com/questions/50597589
复制相似问题