【发布时间】:2020-06-21 11:48:46
【问题描述】:
我有以下场景
我目前使用 appscript 更新我的表单,它工作正常但是我有这个问题,我的表单有问题选择一个国家(从国家的下拉列表中)并且每个选项都映射了每个部分,(比如如果我选择国家作为荷兰,在填写表格时,它会带我到下一部分在指定部分中选择荷兰的城镇),所以现在发生的情况是,只要在表格中添加了新国家,它就会通过下面的脚本在表格中更新,它工作正常,但它重置了为每个国家/地区设置的部分地图,因此我们必须再次重做基于部分的答案!想了解是否有任何方法可以避免重置已设置的基于部分的选项。
代码
var ssID = "sheet ID"; //Global Variable sheet ID
// This is start of function1 to update form Monthly
function formUpdateCC() {
// call your form and connect to the drop-down item
var form = FormApp.openById("form ID");
var country = form.getItemById("ItemID").asListItem();
// identify the sheet where the data resides needed to populate the drop-down - Countrylist
var countrysheet = SpreadsheetApp.openById(ssID).getSheetByName("Country");
// grab the values in the first column of the country tab in sheet - use 2 to skip header row
var countrylist = countrysheet.getRange(2, 1, countrysheet.getMaxRows() - 1).getValues();
var data = [];
// convert the array ignoring empty cells
for (var i = 0; i < countrylist.length; i++)
if (countrylist[i][0] != "")
data[i] = countrylist[i][0];
country.setChoiceValues(data);
}
【问题讨论】:
标签: google-apps-script google-sheets google-forms