Reputation: 530
I'd like to copy a Google Docs document and add text to the copy. This is my code:
function main() {
var template = DriveApp.getFileById(TEMPLATE_DOC_ID);
var copy = template.makeCopy('copied file');
var form = DocumentApp.openById(copy.getId());
form.insertText(0, 'Inserted text.\n');
}
When I run main(), I get the following error: TypeError: Cannot find function insertText in object Document. (line 5, file "Code")
Upvotes: 2
Views: 336
Reputation: 201513
insertText()
.If my understanding is correct, how about this modification?
When you want to put the text to the body, please modify as follows.
From:form.insertText(0, 'Inserted text.\n');
To:
form.getBody().editAsText().insertText(0, 'Inserted text.\n');
When you want to put the text to the paragraph, please modify as follows.
From:form.insertText(0, 'Inserted text.\n');
To:
form.getBody().getParagraphs()[0].insertText(0, 'Inserted text.\n');
If I misunderstood your question and this was not the result you want, I apologize.
Upvotes: 2