ee8291
ee8291

Reputation: 555

make.copy() Google-Api-Script/JavaScript not working

I am trying to copy a Google slide into a Drive folder. When I run the script it looks like my two variables for destination and source are not defined. What am I missing?

   function makeCopy() {
    
      var name = SlidesApp.getActivePresentation().getName() + " Copy ";
      var destination = DriveApp.getFolderById("1234567890");
    
    // gets the current Google Sheet file
      var source = SlidesApp.getActivePresentation();
    
    // makes copy of "file" with "name" at the "destination"
      source.makeCopy(name, destination);
    }

Upvotes: 1

Views: 151

Answers (1)

Diego
Diego

Reputation: 9571

SlidesApp.getActivePresentation() returns a Presentation, but .makeCopy(name, destination) is a File method.

Instead of having source store the presentation, use the presentation's ID to get the file and store it instead.

function makeCopy() {
  var name = SlidesApp.getActivePresentation().getName() + " Copy ";
  var destination = DriveApp.getFolderById("123j3GbzhSB3m8xG-MijssMkynXHxNanl");

  // gets the current Google Sheet file
  var source = DriveApp.getFileById(SlidesApp.getActivePresentation().getId());

  // makes copy of "file" with "name" at the "destination"
  source.makeCopy(name, destination);
}

Upvotes: 2

Related Questions