mias
mias

Reputation: 3

Can I delete a checkbox option through script without deleting the entire item

I want to be able to delete a single choice from a question on my form through gscript without deleting the entire question and I'm not sure if this is even possible to do

Upvotes: 0

Views: 522

Answers (1)

TheMaster
TheMaster

Reputation: 50443

Flow:

  • Get the checkbox item
  • Get all choices of that item as a array
  • Filter that array to remove the choice you don't want
  • Set the filtered array back as choices to that item

Snippet:

function removeOption1() {
  var cbItem = FormApp.getActiveForm()
    .getItems(FormApp.ItemType.CHECKBOX)[0]
    .asCheckboxItem();
  cbItem.setChoices(
    cbItem.getChoices().filter(function(choice) {
      return choice.getValue() !== 'Option 1';
    })
  );
}

To read and practice:

Upvotes: 3

Related Questions