title: How to copy Values from sheets to slides using Google app scripts
body: <p>I am working on a slide that would take dynamic data from Google sheet.</p>
  <ol>
  <li>I want to keep the slide template</li>
  <li>Update the slide values in real-time</li>
  </ol>
  <p>I want to use Google app scripts to connect the data from the sheet to the slide. I am new to Java Scripts and following a <a href="https://www.upbuild.io/blog/inject-google-sheets-data-into-slides/" rel="nofollow noreferrer">tutorial online</a> to achieve this but with no luck.</p>
  <p>My 2 files are set up as follows<a href="https://i.stack.imgur.com/IDh7D.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IDh7D.png" alt="enter image description here" /></a></p>
  <p>and the <a href="https://docs.google.com/presentation/d/1kMPSt03w5xzl6bPS8sUXR7-CGrlilrrYhjKY92y4SaY/edit#slide=id.p" rel="nofollow noreferrer">slides I am working on can be found here</a></p>
  <p><a href="https://docs.google.com/spreadsheets/d/1UccsFtqKKsXhlus4-02dXfJP0ECcCsBUmLNZajJnS_4/edit#gid=20492" rel="nofollow noreferrer">A copy of the data can also be found here</a></p>
  <p><a href="https://www.upbuild.io/blog/inject-google-sheets-data-into-slides/" rel="nofollow noreferrer">The tutorial I am following is found in this link</a></p>
  <p>Below is the code I have implemented but the problem is it does not work and tries to create multiple pages and repeat same value on each page. I only want one page with the values updated from the sheet
  Your help would be grately appareciated. Thank you</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function generateLandingPagesReport() {
    var dataSpreadsheetUrl = "https://docs.google.com/spreadsheets/d/1UccsFtqKKsXhlus4-02dXfJP0ECcCsBUmLNZajJnS_4/edit"; //make sure this includes the '/edit at the end
    var ss = SpreadsheetApp.openByUrl(dataSpreadsheetUrl);
    var deck = SlidesApp.getActivePresentation();
    var sheet = ss.getSheetByName('metrics'); // sheet name
    var values = sheet.getRange('C4:L12').getValues(); // range for values
    var slides = deck.getSlides();
    var templateSlide = slides[0];
    var presLength = slides.length;
   
    values.forEach(function(page){
    if(page[0]){
     
     var Current = page[2];
     var Target = page[3];
     var Emea = page[5];
     var Depac = page[7];
     var Emma = page[9];
     var Comment = page[11];
     
   
     templateSlide.duplicate(); //duplicate the template page
     slides = deck.getSlides(); //update the slides array for indexes and length
     newSlide = slides[2]; // declare the new page to update
     
     
     var shapes = (newSlide.getShapes());
         shapes.forEach(function(shape){
         shape.getText().replaceAllText('{{Current}}',Current);
         shape.getText().replaceAllText('{{Target}}',Target);
         shape.getText().replaceAllText('{{Emea}}',Emea);
         shape.getText().replaceAllText('{{Depac}}',Depac)
         shape.getText().replaceAllText('{{Emma}}',Emma);
         shape.getText().replaceAllText('{{Comment}}',Comment);
         
      });
     presLength = slides.length;
     newSlide.move(presLength);
    } // end our conditional statement
    }); //close our loop of values
  
  //Remove the template slide
  templateSlide.remove();
   
  }</code></pre>
  </div>
  </div>
  </p>