Hi
I had my extremely large form working perfectly, it would reset and delete and then reload. But not it suddenly won't. Something is stuck in the branching I suspect and the 'reset' code is failing.
I am hoping there is a solution. My code has a lot of branching over 53 sections but it is working, until I need to reboot it. I'm not keen on completely recreating the form each time, as my drive is getting rather full with my edits!
I hope you can help, I'm very new to Apps Script and so close to finishing this!
I am probably missing something obvious!
bw
Emma
I've tried resetting the project and undoing my recently changes.
Tried a few different versions of deleting but it stacked on additional questions - hence not deleted:
if (!form) {
form = FormApp.create('TEST1 Form Example');
props.setProperty('TEST1FormId', form.getId());
Logger.log('🆕 Created new form: ' + form.getEditUrl());
} else {
Logger.log('✅ Using existing form: ' + form.getEditUrl());
}
// Clear any existing questions (but leave the page breaks intact)
var items = form.getItems();
for (var i = items.length - 1; i >= 0; i--) {
var item = items[i];
if (item.getType() !== FormApp.ItemType.PAGE_BREAK) {
form.deleteItem(item);
}
}
--------------------------------------------
The one below was working reliably but now I get an error at deleting a page break -
Error
Exception: Invalid data updating form.
setupBranchedForm
@ Code.gs:39
---------------------------------------
// Step 1: Clear all page navigation (branching) to avoid deletion conflicts
const items = form.getItems();
for (let item of items) {
if (item.getType() === FormApp.ItemType.MULTIPLE_CHOICE) {
const mc = item.asMultipleChoiceItem();
const choices = mc.getChoices().map(choice =>
mc.createChoice(choice.getValue(), FormApp.PageNavigationType.CONTINUE)
);
mc.setChoices(choices);
}
Logger.log('📄 Items' +item.getType());
}
// Step 2: Now safely delete all items (questions + page breaks)
for (let i = items.length - 1; i >= 0; i--) {
Logger.log('📄 Delete' + items[i].getType());
form.deleteItem(items[i]);
}