Gianluca G
Gianluca G

Reputation: 11

The parameters (DocumentApp.ListItem) don't match the method signature for DocumentApp.Body.appendParagraph

Trying to connect a google spreadsheet and a google document together in google script and I am on what I have done wrong. error messages:

(anonymous)@Code.gs:12
[email protected]:11

function myFunction() {

  var docTemplateId = "144IYPXNG2Yqb2XqQCv91CUpQ8NMoaZrwBtq-pW-NaQM";
  var docFinalId = "1vXZn6NVwI2ee5RzCLvJCL6nXWSWdcKMZ9uzvBjtyRzY";
  var wsId = "1-4aGpNWi2gtVw2kIjKM7B5tRTQhrT-eoSRxBr5K_AIk";

  var docTemplate = DocumentApp.openById(docTemplateId);
  var docFinal = DocumentApp.openById(docFinalId);
  
  var templateParagraphs = docTemplate.getBody().getParagraphs();
  templateParagraphs.forEach(function(p){
    docFinal.getBody().appendParagraph(p.copy().replaceText("{ID}", "I"));

  });
}

Upvotes: 1

Views: 979

Answers (1)

Wicket
Wicket

Reputation: 38295

After

var docFinal = DocumentApp.openById(docFinalId);

add

var body = docFinal.getBody();

then replace

docFinal.getBody().appendParagraph(p.copy().replaceText("{ID}", "I"));

by

 var q = body.appendParagraph(p.copy());
 q.replaceText("{ID}", "I");

Upvotes: 1

Related Questions