title: Google Script - Forms - Issues Deleting Page Breaks/Sections - "Invalid data updating form"
body: <p>I am having an issue with the following code when trying to iterate through the items in a form and delete them to make way for new sections/questions.  However, I sometimes get the following error "Invalid data updating form".  I have worked around this multiple times now, but it keeps coming back up.  My current workaround has been to set the section title to "", which made it available to delete.  Previously, I didn't need to do this until today.</p>
  
  <p>My question: What is the best way to iterate through the items in a form and delete them from a starting point and not encounter this error?</p>
  
  <p>Reference:<br>
  f = the current active form<br>
  f_items = all of the items of the form in an array   </p>
  
  <pre><code>function clearForm()
  {
      var clearQ = find(f_items, "Select Appointment Date/Time")+1;
      var f_i_len = f.getItems().length-1;
      var clear = clearQ;
      while(clear &lt;= f_i_len &amp;&amp; clear &gt;= clearQ)
      {
          var item = f.getItems()[clear];
          Logger.log(item.getTitle() + " | " + item.getType());
          Logger.getLog();
          if(item.getType() == "PAGE_BREAK")
          { item.asPageBreakItem().setTitle(""); }
          f.deleteItem(clear);
          f_i_len = f.getItems().length-1;
          clear++;
      }
  }
  
  function find(src, name)
  {
      var s_len = src.length;
      for(var iter = 0; iter &lt; s_len; iter++)
      {
          var s = src[iter].getTitle();
          if(s == name)
          { return iter; }
      }
      return -1;
  }
  </code></pre>