google-apps-script - 如何在谷歌应用脚本中使用 setrequired()
问题描述
我对谷歌应用脚本很陌生,因为谷歌表单不能执行条件要求的功能,我需要自己修改表单。我在谷歌应用程序脚本网站中找到了这段代码,我尝试使用它来测试我是否能够实现我想要的。我想实现什么:
- 对于“你喜欢猫还是狗?” 问题,如果用户选择猫,“评价你的兴趣”问题将自动设置为必填。
我从我拥有的代码中得到了什么:
- if 语句没有按预期工作。无论 if 语句条件如何,“评价您的兴趣”问题都设置为必填。
以下是代码:
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());
}
解决方案
推荐阅读
- c++ - 在 Visual Studio 中调试 c++ 代码指针时遇到问题
- angular - TestBed 模拟服务
- sql - 是否可以从 SQL Server 调用 Web 服务?
- jenkins - 在 'git url' jenkins piplines 中使用变量
- python - 为什么我的正则表达式函数不起作用?
- python - Pyparsing parseaction 和列表类型错误
- python - 调整引用另一个数组的numpy数组的大小
- javascript - 为什么这个绑定的剔除元素变得未定义?
- php - 如何一起选择2个sql表?
- kubernetes - 为什么 Istio “身份验证策略”示例页面没有按预期工作?