Get the Document Explainer

Aim of the puzzle: Use Apps Script to get a document from Docs and print its name.

Walk through of the solution: Every document in Docs has a unique id. An id is a long string of characters and numbers, like this: accb4372522af72303e7bcd67a8e953189205bb6728a.

Apps Script has custom code functions that connect to Docs. One example is DocumentApp.openById(), which takes an id and returns the matching document from Docs.

In the code that you start off with, the document with the id id1 is accessed using DocumentApp.openById(id1) and saved to the variable doc1. Then, its name is stored in the doc1Name variable usingdoc1.getName() and printed to the console.

To complete the puzzle, create a variable called doc2 that stores the document accessed by DocumentApp.openById(id2). Then, create a variable called doc2Name that stores the name of doc2 using doc2.getName(). Finally, print doc2Name to the console.

Sample code solution:

let id1 = '1VFYFgTvngQzMgm-x1Kyejv1fiTWVTahG9G8x2a76sAM';
let id2 = '1NH4DAJhLXW2f4DNi0ciEDoCOLe4cFbp0s_qMFRgfR84';

let doc1 = DocumentApp.openById(id1);
let doc1Name = doc1.getName();

let doc2 = DocumentApp.openById(id2);
let doc2Name = doc2.getName();

JavaScript concepts: Variables, Strings

Apps Script concepts: DocumentApp, openById(), .getName()

1 Like