I have two scripts that work well separately but I need to combine them.
What I am trying to achieve is that from a Google Sheets, someone will run a script and:
For point 1 I have this code:
function createFolderAndFiles() {
const templateGetStarted = '<ID OF MY TEMPLATE DECK>';
let sheet = SpreadsheetApp.getActive().getSheetByName('Generate');
let data = sheet.getDataRange().getValues();
let wbrDate = data[1][0];
let getStarted = data[1][1];
DriveApp.getFileById(templateGetStarted).makeCopy(`WBR - ${wbrDate}`)
}
And for point 2 I have this code:
function fillTemplate() {
var PRESENTATION_ID = "<THE ID OF THE JUST CREATED COPY OF THE TEMPLATE DECK IN POINT 1>";
var presentation = SlidesApp.openById(PRESENTATION_ID);
var values = SpreadsheetApp.getActive().getSheetByName('Data').getDataRange().getValues();
values.forEach(function(row) {
var templateVariable = row[0]; // First column contains variable names
var templateValue = row[1]; // Second column contains values
presentation.replaceAllText(templateVariable, templateValue);
});
}
So as I mentioned, they work great separetely. I just need to find a way to combine them both into 1 function that you can run and a copy of the template deck will be made and it will be filled automatically with data from the spreadsheet.
Any help is much appreciated!
You can try meeting your last line of the first function and first line of the second one
var PRESENTATION_ID = DriveApp.getFileById(templateGetStarted).makeCopy(`WBR - ${wbrDate}`).getId()