Mishal
Mishal

Reputation: 430

TypeError: Cannot read property 'insertSlide' of null (line 60, file "Code")

Would be grateful for any guidance on how to fix this error. Please see below code which gives the error,

  // Copy a slide from another presentation and inserts it.
  var otherPresentation = SlidesApp.openById('1Fz6YWCyLIdHfDoonz-40qRlmnNCWwROIQjXqYwmRxS8');
  var currentPresentation = SlidesApp.getActivePresentation();
  var slide_v1 = otherPresentation.getSlides[0];
  var insertionIndex = 1;
  currentPresentation.insertSlide(insertionIndex, slide_v1);

Upvotes: 0

Views: 345

Answers (1)

Mishal
Mishal

Reputation: 430

Thanks to Tanaike and some changes to the code - this has been solved. Please see updated code below.

  // Copy a slide from another presentation and inserts it.
  var otherPresentation = SlidesApp.openById('1Fz6YWCyLIdHfDoonz-40qRlmnNCWwROIQjXqYwmRxS8');
  var currentPresentation = SlidesApp.openById(documentId);
  var slide_v1 = otherPresentation.getSlides()[0];
  var insertionIndex = 1;
  currentPresentation.insertSlide(insertionIndex, slide_v1);

Using [0] has definitely helped after the getSlides()

I have removed .duplicate() because it creates duplicates on the template.

Upvotes: 1

Related Questions