title: Google Scripts, for loop not working as expected
body: <p>I am trying to create a dynamic googledoc that uses %Address0%, %Address1%, %Address2%, etc. to populate from a spreadsheet that contains the information. my current code works for all of the first %description0% 's but the susequent %desription1%,%description2% are not populating. Im guessing my for-loop is not iterating past the first iteration or for some reason the body cannot be modified twice, but I can't find anything in the supporting documentation that would give me that idea.</p>
  
  <p>Also, I ruled out the possibility of it being something wrong with the var data, I can get all the properties one at a time, for example: I can get the %Address0%, %Type0%, %Price0% to populate correctly OR I can get %Address1%, %Type1%, %Price1% but I can't get them to do it all at once.</p>
  
  <pre><code>// create a menu
  function onOpen() {
    var menuEntries = [ {name: "Create CMA", functionName: "CreateCMA"}];
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    ss.addMenu("CMA Generator", menuEntries);
  }
  
  function CreateCMA() {
    var templateid = "1uLC41M1B0KjtC_AlxFAT2h2_9HPLsLSk4HPhXgq2ebY"; // template file id
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getActiveSheet();
    var data = sheet.getRange(2,1,6,11).getValues(); // starting with row 2 and column 1 as our upper-left most column
    var docid = DriveApp.getFileById(templateid).makeCopy().getId();
    // Create our number formatter.
    var formatter = new Intl.NumberFormat('en-US', {
    style: 'currency',
    currency: 'USD',
    });
    var doc = DocumentApp.openById(docid);
  
    for (var r = 0; r &lt; 6; r++){
      var body = doc.getBody();
      var row = data[r];
      body.replaceText("%Address" + r + "%", row[0]);
      body.replaceText("%Type" + r + "%", row[1]);
      body.replaceText("%Price" + r + "%", formatter.format(row[2]));
      var date = row[3];
      var dateform = Utilities.formatDate(date, "+5", "dd MMM yyyy");
      body.replaceText("%Date" + r + "%", dateform);
      body.replaceText("%Built" + r + "%", row[4]);
      body.replaceText("%Square_ft" + r + "%", row[5]);
      body.replaceText("%Bedroom" + r + "%", row[6]);
      body.replaceText("%Bath" + r + "%", row[7]);
      body.replaceText("%Assessed_Val" + r + "%", formatter.format(row[8]));
      body.replaceText("%Initial_Ask" + r + "%", formatter.format(row[9]));
      var post = row[10];
      var postform = Utilities.formatDate(post, "+5", "dd MMM yyyy");
      body.replaceText("%Day_Posted" + r + "%", postform);
    }
      doc.saveAndClose();
  
  }
  </code></pre>