1
votes

I have a spreadsheet containing a script. In this script I created another spreadsheet, called TP. I want to set Triggers in this TP spreadsheet. That is easy for the onopen trigger.

    ScriptApp.newTrigger("agendaCheck")
    .forSpreadsheet(TP)
   .onOpen()
   .create();

But for the time based trigger I can't do this.

     ScriptApp.newTrigger("agendaCheck")
     .forSpreadsheet(TP)
    .timeBased()
    .atHour(3)
    .everyDays(1) 
    .create();

This runs an error: can't find function timeBased in object SpreadsheetTriggerBuilder...

1
I m thinking about a workaround. I could create the TP spreadsheet by copying a template, which has a script. In this local script I put a function (makeTimeBaseTrigger). Then I set an onopen trigger form the parent spreadsheet running the makeTimeBaseTrigger function. Only problem is that I propably have to autorize first time it runs... So no good .. - Bert A

1 Answers

0
votes

The SpreadsheetTriggerBuilder class only gives access to simple triggers (onOpen(), onEdit(), etc). You need to use:

ScriptApp.newTrigger('myFunction')
   .timeBased()
   .atHour(3)
   .everyDays(1)
   .create();

and bind myFunction to a function which accesses the TP spreadsheet.