我需要一致地重复使用特定的表单 URL,同时保持使用脚本重新生成表单的能力。为此,我编写了一个删除表单数据的函数。最初,我让它运行 form.getItems() 并看到主题中的错误。认为这是因为我不是程序员并且我的代码可能非常低效,所以我重新编写了例程来分解每个 itemType 和每个项目删除之间的延迟。这让我的日常工作变得异常缓慢,但如果它能让谷歌允许它工作,我可以处理缓慢。
这是我目前拥有的代码,不幸的是,它仍然给我同样的错误。我的问题实际上是谷歌的后端问题吗???是我的代码吗?两个都?
我有表单信息的全局变量:
var formurl='*a url that works for me*'
var form=FormApp.openByUrl(formurl);
function DeleteFormItems() {
var formcheckboxitems=form.getItems(FormApp.ItemType.CHECKBOX);
var formdateitems=form.getItems(FormApp.ItemType.DATE);
var formdatetimeitems=form.getItems(FormApp.ItemType.DATETIME);
var formdurationitems=form.getItems(FormApp.ItemType.DURATION);
var formgriditems=form.getItems(FormApp.ItemType.GRID);
var formimageitems=form.getItems(FormApp.ItemType.IMAGE);
var formlistitems=form.getItems(FormApp.ItemType.LIST);
var formmultiplechoiceitems=form.getItems(FormApp.ItemType.MULTIPLE_CHOICE);
var formpagebreakitems=form.getItems(FormApp.ItemType.PAGE_BREAK);
var formparagraphtextitems=form.getItems(FormApp.ItemType.PARAGRAPH_TEXT);
var formscaleitems=form.getItems(FormApp.ItemType.SCALE);
var formsectionheaderitems=form.getItems(FormApp.ItemType.SECTION_HEADER);
var formtextitems=form.getItems(FormApp.ItemType.TEXT);
var formtimeitems=form.getItems(FormApp.ItemType.TIME);
for (var i = formcheckboxitems.length-1; i >= 1; i--) {
Utilities.sleep(2000)
form.deleteItem(i);
};
for (var i = formdateitems.length-1; i >= 1; i--) {
Utilities.sleep(2000)
form.deleteItem(i);
};
for (var i = formdatetimeitems.length-1; i >= 1; i--) {
Utilities.sleep(2000)
form.deleteItem(i);
};
for (var i = formdurationitems.length-1; i >= 1; i--) {
Utilities.sleep(2000)
form.deleteItem(i);
};
for (var i = formgriditems.length-1; i >= 1; i--) {
Utilities.sleep(2000)
form.deleteItem(i);
};
for (var i = formimageitems.length-1; i >= 1; i--) {
Utilities.sleep(2000)
form.deleteItem(i);
};
for (var i = formlistitems.length-1; i >= 1; i--) {
Utilities.sleep(2000)
form.deleteItem(i);
};
for (var i = formmultiplechoiceitems.length-1; i >= 1; i--) {
Utilities.sleep(2000)
form.deleteItem(i);
};
for (var i = formparagraphtextitems.length-1; i >= 1; i--) {
Utilities.sleep(2000)
form.deleteItem(i);
};
for (var i = formscaleitems.length-1; i >= 1; i--) {
Utilities.sleep(2000)
form.deleteItem(i);
};
for (var i = formsectionheaderitems.length-1; i >= 1; i--) {
Utilities.sleep(2000)
form.deleteItem(i);
};
for (var i = formtextitems.length-1; i >= 1; i--) {
Utilities.sleep(2000)
form.deleteItem(i);
};
for (var i = formtimeitems.length-1; i >= 1; i--) {
Utilities.sleep(2000)
form.deleteItem(i);
};
for (var i = formpagebreakitems.length-1; i >= 1; i--) {
Utilities.sleep(2000)
form.deleteItem(i);
};
}
这是我更新的脚本,我仍然遇到主题中提到的错误,但它在收到消息之前取得了更多进展(删除了几个项目)。
var formurl='*a url that works for me*'
var form=FormApp.openByUrl(formurl);
function DeleteFormItems() {
var formitems=form.getItems();
Logger.log('There are '+formitems.length+' total form items');
for (var i = 1; i <= formitems.length-1; i++) {
Utilities.sleep(2500)
form.deleteItem(formitems[i]);
};
}