I have a flow that sends data from a google sheet into google slides. For each row in google sheets, it will generate one slide. When I do the initial run, it works fine. However, when I then add a new or delete an existing row in the google sheets, my slides currently does not update properly.
Issue 1: I have 2 initial rows (see below), and I then add a new row, the script then generates the initial 2 slides PLUS 3 additional slides (initial two slides + new slide) which leads to duplicates.
Issue 2: When I delete a row in the google sheets and then re-run the script, the slide (for the deleted row) still exists and is not removed from the deck.
I think the easiest way is the remove all filled slides and only use the raw slide (with variables) and then start re-filling (see raw slide below).
Here is the google sheet example (assuming we start with 2 rows):
Here is the script I run:
function generateSlides() {
var dataSpreadsheetUrl = "https://docs.google.com/spreadsheets/7Nsah";
var ss = SpreadsheetApp.openByUrl(dataSpreadsheetUrl);
var deck = SlidesApp.getActivePresentation();
var sheet = ss.getSheetByName('tab_1');
var values = sheet.getRange('A2:B1000').getValues();
var slides = deck.getSlides();
var templateSlide = slides[1];
var presLength = slides.length;
values.forEach(function(page){
if(page[0]){
var Email = page[1];
var Name = page[0];
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('{{Email}}',Email);
shape.getText().replaceAllText('{{Name}}',Name);
});
presLength = slides.length;
newSlide.move(presLength);
} // end our conditional statement
}); //close our loop of values
//Remove the template slide
templateSlide.remove();
}
Here is the raw slide which is filled with each run (and therefore overwritten with the first run which is part of the problem).

So, the issue is that after the initial run the raw slide form does not exist anymore as it was filled with Name/Email. However, with every subsequent run, I want to use only the raw slide (again) and remove any existing slides which gives it the flushing effect. How would I do this? Any help is appreciated! Thanks
onChange. Are you still interested in a solution? - ziganotschka