I am trying to create a copy of a template document and edit some text in it using the following code :
const destinationFolder = DriveApp.getFolderById(folderId) //folder where to save the document
const copy = templateDoc.makeCopy(customDocName.toString(), destinationFolder); //make a copy of the template document
const doc = DocumentApp.openById(copy.getId()) //open the copy
const body = doc.getBody();
//update the template with data
body.replaceText('<text1>', 'replacementText');
body.replaceText('<text2>', 'replacementText');
I am able to create a copy of the document, rename it and save it in the specified folder . I am getting the following error at line 3 : Exception: The document is inaccessible. Please try again later.
I have looked for the solutions and have tried all but nothing worked.
Here is all that I have tried :
- Logout and login again
- Enabled all relevant api under resources
- Moved the app script under a GCP project as someone suggested that we no longer can access a doc directly from app script.
- Enabled all relevant api's in GCP