Open google doc by id

What I'm trying to do is make a copy of the doc document, add the sheet data to a new file. I use the URL of the document as an identifier. However, when I try to access the file, I get this error "Document is missing (perhaps it was deleted?) (Line 21)" Line 21

var templateid = "URL"; var file = DocumentApp.openById(templateid); 

Can anyone advise what the problem is?

+4
source share
1 answer

The document identifier is not the URL of the document, but it is the UID generated when the document was created, for example, the id value after var id = createDocWithTable("doc with table") .

You need to track this identifier separately. If you have a document object, you can get it using the getId() method. The identifier is also encoded in the URL, so https://docs.google.com/document/d/3ckYOu8kuIfBzbu-Dtu9XwGHUnUJG32PK7wHe5xMv3VG/ has the document identifier 3ckYOu8kuIfBzbu-Dtu9XwGHUnUJG32PK7wHe5xMv3VG

+6
source

All Articles