title: Google forms duplicates sections when running Google Apps Script multiple times
body: <p>I've got a code in Google Apps Script to automatically populate a Google Form. It works perfectly, but there's one big problem. When I run the script multiple times, the Forms copies itself. So, instead of overwriting the previous run, it adds a whole new (identical) Form. For example: after running the code one time, it shows 4 sections. But when I run it two times, it shows 8 sections, and so on.
  Does anybody know how to solve this?
  Here's the used code:</p>
  <pre><code>function rosterMaker() {
    //spreadsheet id of the rosters
    var SHEET_ID = FormApp.getActiveForm().getDestinationId();
    var ss = SpreadsheetApp.openById(SHEET_ID)
    var form = FormApp.getActiveForm();
                     
    var sheets = ss.getSheets().filter(function(sheet) {return sheet.getName().match(/Roster/gi);});
    
    //add multiple choice item
    var classSelect = form.addMultipleChoiceItem();
    classSelect.setTitle('Choose a class');  
    
    var classChoices = [];
    for(var i = 0; i &lt; sheets.length; i++) {
      var className = sheets[i].getName();
      
      var classSection = form.addPageBreakItem()
      .setTitle(className)
      .setGoToPage(FormApp.PageNavigationType.SUBMIT);
      
      var students = getStudents(sheets[i]);
      
      var studentSelect = form.addCheckboxItem()
      .setTitle(className + 'absent')
      .setHelpText('Select the students who are absent from  this class');
     
      
      var studentChoices = [];
      for(var j = 0; j &lt; students.length; j++) {
        studentChoices.push(studentSelect.createChoice(students[j]));
      }
      
      studentSelect.setChoices(studentChoices);
      
      classChoices.push(classSelect.createChoice(className, classSection));
    }
    
    classSelect.setChoices(classChoices);
  }
  
  
  function getStudents(sheet) {
    var studentValues = sheet.getDataRange().getValues();
    
    var students = [];
    for(var i = 1; i &lt; studentValues.length; i++) {
      students.push(studentValues[i].join(' '));
    }
    return students;
  }
  </code></pre>