In Google App Script, why does my refresh() function not refresh to the most recent data?

49 Views Asked by At

I have a Google Slides deck that has embedded charts from Google Sheets. I wrote a Google App Script that is intended to automatically refresh the charts, but it is generating inaccurate refreshes.

In other words, the for loop is successfully refreshing the 'sheetsCharts', BUT the refreshed charts in Google Slides do not match the charts in Google Sheets. It seems like it's updating the refreshed Google Slides charts with data from an old refresh or something. Not sure...

Does anybody know why this might be happening?

// Open the active presentation
  var presentation = SlidesApp.getActivePresentation();
  
  // Get the slides in the presentation
  var slides = presentation.getSlides();

// Refresh embedded Google Sheets charts in each slide
  for (var x = 0; x < slides.length; x++) {
    var slide = slides[x];
    var sheetsCharts = slide.getSheetsCharts();

    for (var y = 0; y < sheetsCharts.length; y++) {
      var shChart = sheetsCharts[y];
      shChart.refresh(); // Refresh the embedded Google Sheets chart
    }
  }

I have tried creating new charts and testing different datasets, but the problem remains.

0

There are 0 best solutions below