Andi Nuruljihad
Andi Nuruljihad

Reputation: 88

Script Can't Open Document (Inaccessible, Please Try Again)

I'm trying to create a copy of a document and populate it with data from a spreadsheet. I can successfully create the copy but the script can't seem to access it to edit its contents. Here's the code:

var file = DriveApp.getFileById('1mWFhZpZVJpYJleg9n5qq3tr7EHwUIlbM');
var copy = file.makeCopy('SKPembimbing_' + nim, folder).getId();
var doc = DocumentApp.openById(copy);
var body = doc.getBody();

It always gives me an error at the 3rd line when it tries to open the document for editing.

(Exception: Document is inaccessible. Please try again later.)

I saw another thread from last year with the same exact question but without a solution. I've been working all night trying to get this darn thing to work. Does it have to do with my scope? I'm running it on a trigger on edit.

Upvotes: 3

Views: 1263

Answers (1)

Andi Nuruljihad
Andi Nuruljihad

Reputation: 88

I found the solution:

The template document I was copying was a .docx file, NOT a Google Doc. The copied file was thus also a .docx file so was inaccessible from the DocumentApp. All I had to do was convert it to a Google Document.

Upvotes: 2

Related Questions