JennyS
JennyS

Reputation: 1

Getting error "Exception: The match text should not be empty"

Trying to automate a Google Slides presentation from Sheets using App Script. Experiencing an error and inconsistent results when I run the script

function fillTemplate() {
var Presentation_ID="1lManUPdT6g5t4q0kanfy1wWwX6wF9bB9kRNn9VVsvPQ";

var Presentation=SlidesApp.openById(Presentation_ID);
var values= SpreadsheetApp.getActive().getDataRange().getValues();

values.forEach(function(row){
var templateVariable= row[0];
var templateValue= row[2];
Presentation.replaceAllText(templateVariable, templateValue);

});

}
|   |   |
|---|---|
|Error|Exception: The match text should not be empty.
<br>(anonymous) @ Code.gs:10<br>fillTemplate    @ Code.gs:7|

Upvotes: -1

Views: 633

Answers (1)

Cooper
Cooper

Reputation: 64100

This should prevent the error:

function fillTemplate() {
  const Presentation = SlidesApp.openById("id");
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Your Sheet Name");
  var vs = sh.getDataRange().getValues();
  vs.forEach((r, i) => {
    if (r[2] && r[0]) {
      Presentation.replaceAllText(r[0], r[2]);
    } else {
      Logger.log(`Error on iteration ${i}`)
    }
  });
}

Upvotes: 1

Related Questions