Delete All Google Form Questions via AppScript

delete all google form questions using appscript

while building MagicForm.app we faced an issue having too many quiz questions in the google form, deleting them one by one was so tedious.

so i wrote appscript code to delete them.

javascript
function deleteAllQuizQuestions() {
  // Open the form by ID (replace 'your-form-id' with your actual Form ID)
  var form = FormApp.openById('1v6WnprnH4eEpqK3P2CSw1ULaSF-5a1xHyY9i1RHp94E');
  
  // Get all items in the form
  var items = form.getItems();
  
  // Iterate over all items in reverse order to avoid indexing issues when deleting
  for (var i = items.length - 1; i >= 0; i--) {
    var item = items[i];
    // Check if the item is of a type that can be used for quizzes
    if (item.getType() === FormApp.ItemType.MULTIPLE_CHOICE ||
        item.getType() === FormApp.ItemType.CHECKBOX ||
        item.getType() === FormApp.ItemType.TEXT ||
        item.getType() === FormApp.ItemType.PARAGRAPH_TEXT ||
        item.getType() === FormApp.ItemType.SCALE ||
        item.getType() === FormApp.ItemType.GRID ||
        item.getType() === FormApp.ItemType.DATE ||
        item.getType() === FormApp.ItemType.TIME ||
        item.getType() === FormApp.ItemType.DATETIME ||
        item.getType() === FormApp.ItemType.DURATION) {
      // Delete the item
      form.deleteItem(i);
    }
  }
}
Delete All Google Form Questions via AppScript