title: Google apps script function appenParagraph doesn't append to the end of the document
body: <p>I have this piece of code and I wonder how to append paragraphs at the end of a recently opened document:</p>
  
  <pre><code>function foo()
  {
    var doc = DocumentApp.getActiveDocument();
    var doc_id = doc.getId();
    var body = doc.getBody();
  
    body.appendParagraph('1');
    body.appendParagraph('2');
  
    doc.saveAndClose();
    doc = DocumentApp.openById(doc_id);
    body = doc.getBody();
  
    body.appendParagraph('3');
  }
  </code></pre>
  
  <p>I expected the result was "1 2 3" but it is "3 1 2".</p>
  
  <p>I've been playing with setCursor without success.</p>
  
  <p>Thanks in advance</p>