当我尝试迭代表单中的项目并删除它们以为新的部分/问题让路时,我遇到了以下代码的问题。但是,我有时会收到以下错误“无效的数据更新表单”。我已经多次解决这个问题,但它不断出现。我当前的解决方法是将部分标题设置为“”,这样就可以删除它。以前,直到今天我才需要这样做。
我的问题:迭代表单中的项目并从起点删除它们并且不会遇到此错误的最佳方法是什么?
参考:
f = 当前活动形式
f_items = 数组中表单的所有项目
function clearForm()
{
var clearQ = find(f_items, "Select Appointment Date/Time")+1;
var f_i_len = f.getItems().length-1;
var clear = clearQ;
while(clear <= f_i_len && clear >= clearQ)
{
var item = f.getItems()[clear];
Logger.log(item.getTitle() + " | " + item.getType());
Logger.getLog();
if(item.getType() == "PAGE_BREAK")
{ item.asPageBreakItem().setTitle(""); }
f.deleteItem(clear);
f_i_len = f.getItems().length-1;
clear++;
}
}
function find(src, name)
{
var s_len = src.length;
for(var iter = 0; iter < s_len; iter++)
{
var s = src[iter].getTitle();
if(s == name)
{ return iter; }
}
return -1;
}
我遇到的问题是,我试图删除的 PageBreakItem 是表单中前面条件答案的目的地。
下面是我的代码,我需要删除某个项目之后的所有内容,该项目链接到我需要删除的部分,因此我能够使用 while 循环向后迭代。
function getParentNameItem_(form, form_items){
//finds the item with conditional navigation to what you want to delete
var parent_name_item = find_(form_items, "Your Name");
parent_name_item = parent_name_item.asListItem();
//clears all choices which breaks the navigation dependency
//this frees up the items to be deleted
parent_name_item.setChoices([parent_name_item.createChoice("")]);
var size = form_items.length - 1;
//iterates from the end back to the last question I want to keep
while(form_items[size].getTitle() != "Your Name"){
//this can take either the item itself or the index as I've done
form.deleteItem(size);
size--;
}
/*I rebuild the choices for parent_name_item
later based on information from a spreadsheet
which I also use to determine the content of
the PageBreakItems I just deleted*/
return parent_name_item;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)