I would like to install a time based trigger on multiple Google Sheets using Google Apps Scripts and can't figure out how to do so. I know these can be added through the UI but I was hoping to find a programmatic way to do this. I have tried this code:
function initializeTrigger(sheetID){
var sheet = SpreadsheetApp.openById(sheetID);
ScriptApp.newTrigger('myLibrary.myFunction')
.forSpreadsheet(sheet)
.timeBased()
.atHour(9)
.everyDays(1)
.create();
}
function installMultipleTriggers(){
var sheetList = [sheetID1, sheetID2, sheetID3];
for (var i = 0; i < sheetList.length; i++)
{
initializeTrigger(sheetList[i]);
}
}
But when I run this I receive the error:
TypeError: Cannot find function timeBased in object SpreadsheetTriggerBuilder.
Which makes sense I guess, because according to the documentation, the SpreadsheetTriggerBuilder class doesn't have a method named timeBased()... Does anyone know how to add time-based triggers to multiple Google Sheets?