title: Get document's URL/ID after a file was copied
body: <p>I am trying to have the newly copied document to be updated upon completion of being copied, added to a different folder and its root file removed. The Google script is not able to find the newly copied file. The error is in the lower half of the code surrounded by asterisks with TypeError.</p>
  
  <p>I suspect it has to do with the line of <code>var doc = DocumentApp.getActiveDocument();</code>. I am not sure how to get the URL of the newly copied document (<code>file2</code> or <code>Date - Weekly Agenda</code>).</p>
  
  <pre><code>  function copyupdateWeeklyAgenda() {
    var file = DriveApp.getFileById("FILEKEY");
    var source_folder = DriveApp.getFolderById("FOLDERKEY");
    var dest_folder = DriveApp.getFolderById("FOLDERKEY");
    // Make a backup copy.
    var file2 = file.makeCopy('Date - Weekly Agenda');
    dest_folder.addFile(file2);
    source_folder.removeFile(file2);
  
  //START Update Weekly Agenda Data ---
    var ssUrl = 'https://whydoyouwanttoknow.com';
    var sheetName = 'Sheet1';   // name of sheet to use
    var rangeName = 'A1:B2';    // range of values to include 
    var values = SpreadsheetApp.openByUrl(ssUrl)
                               .getSheetByName(sheetName)
                               .getRange(rangeName)
                               .getValues();
    var doc = DocumentApp.getActiveDocument();
    **var body = doc.getBody();** &lt;--- TYPEERROR: Cannot call method "getBody" of null.
    var ranges = doc.getNamedRanges('embeddedSheet-range');
    if (ranges.length == 0) {
      var table = body.appendTable(values);
    ...ETC.
  </code></pre>