Reputation: 51
I had some old code that worked great 5 years ago in taking a Google Form and filling in a pre-designed template from the information. I haven't needed to use it in awhile, but now I have a similar project and was trying to revitalize the outdated code. I have one error I cannot figure out or find an answer to online. Please Help!
The relevant part of the code is:
//Create a copy of template
var copy = DriveApp.getFileById(docTemplate)
.makeCopy(docName+' TEST ')
.getId();
// Open the temporary document
var copyDoc = DocumentApp.openById(copy);
The first part works, a copy of the document is created in my Google Drive and var copy returns the value of the new document ID.
I get the error message "The document is inaccessible. Please try again later. (line 79, file "Code")"
line 79 of code is the : "var copyDoc = DocumentApp.openById(copy);".
I have tried a few different codes for opening a file and they are all returning the same error message.
Upvotes: 5
Views: 11308
Reputation: 291
Just want to share my resolution to this problem. I know is an old thread but there may be other people in the future who will stumble upon this thread who are still trying to fix this issue.
I encountered this error just now. It turns out that the file that was cloned and tried to open after was a ".docx" file. A MS word file that was uploaded to google drive. The DocumentApp API can only open google docs files. To fix this, just open the the base file that was being cloned then File > Save as Google Docs. This will create a new file. Use that as the new base file.
Upvotes: 29
Reputation: 1104
Actually since the new versions, you can't just run the scripts... I spend the hole day on this.
Once I've done this, files started opening files. The main problem is that a trigger on a form (or otherwise) can't open docs for security. Which is a pain since you now need to do a bunch of other stuff on top...
Upvotes: 0
Reputation: 64040
This works for me:
function runOne() {
var docTemplate='id string';
var file=DriveApp.getFileById(docTemplate);
var copy = file.makeCopy(file.getName()+'TEST').getId();
var copyDoc = DocumentApp.openById(copy);
copyDoc.getBody().appendParagraph("This is new text.");
copyDoc.saveAndClose();
}
Of course, when the script opens the document by Id it does not actually open it with a user interface it just opens it on the server. But when I opened it, sure enough that appendedParagrahp was there.
Upvotes: 1