title: How do to resolve this error "Exception: Invalid argument: replacement"?
body: <p>I have a function that makes a copy of an existing document (template) and then merges data in dynamically by matching the header names to the tags listed within the document. The function worked without any problems, but now suddenly I'm receiving an error message whenever it tries to merge. Can anyone give me some insight into what the issue might be?</p>
  
  <p><strong>Error Message</strong>:
  Exception: Invalid argument: replacement</p>
  
  <p>The weird thing is that it doesn't prevent the information from merging, but the error does stop the function from completing the other tasks.</p>
  
  <p><strong>Line with the error</strong></p>
  
  <pre><code>headers.forEach(function(e){
       body.replaceText("&lt;&lt;"+e+"&gt;&gt;",data[e]);
      return;
    });
  </code></pre>
  
  <p>The whole code:</p>
  
  <pre><code>function documents(sheet, data){
       var headers = Object.keys(data[0]);     
       var docsToMerge = data.map(function(e){      
         var name = e.location +" - "+e.employeeLastName+", "+e.employeeFirstName+" - "+e.docName+" "+Utilities.formatDate(new Date(e.effectivePayDate), "UTC-4", "M/d/yy");
         var newDoc = DriveApp.getFileById(e.template).makeCopy(name, DriveApp.getFolderById(e.folderId));  
         e.documentLink = newDoc.getUrl();
         e.documentId = newDoc.getId();
         return e;
       });
  
        docsToMerge.forEach(function(e){
          mergeDocuments(e, headers, signatureFolderId);
        });
  }
  
  function mergeDocuments(data, headers){
    var id = DocumentApp.openByUrl(data.documentLink).getId();
    var doc = DocumentApp.openById(id);      
    var body = doc.getBody();
  
    headers.forEach(function(e){
       body.replaceText("&lt;&lt;"+e+"&gt;&gt;",data[e]);
      return;
    });
    doc.saveAndClose();
    return;
  }
  </code></pre>