0

I am trying to create a time based trigger for a gmail add-on. Here is the sample code.

function myFunction()
{
  // do something

  // then create a time based trigger

     ScriptApp.newTrigger("dummy_fun")
    .timeBased()
    .everyHours(12)
    .create();

  //return the card
}

function dummy_fun()
{
   //do something
}

This is how my manifest file look like.

{
  "timeZone": "America/Whitehorse",
  "dependencies": {},
  "oauthScopes": [
    "https://www.googleapis.com/auth/gmail.addons.execute",
    "https://www.googleapis.com/auth/gmail.addons.current.message.readonly",
    "https://www.googleapis.com/auth/script.scriptapp"
  ],
  "runtimeVersion": "V8",
  "gmail": {
    "name": "Time Trigger Test",
    "logoUrl": "https://www.gstatic.com/images/icons/material/system/1x/receipt_black_24dp.png",
    "contextualTriggers": [
      {
        "unconditional": {},
        "onTriggerFunction": "myFunction"
      }
    ]
  }
}

Now the trigger is created when I press run button in the app script editor. But I get following exception every time when I open/refresh the add on in my gmail account.

Exception: Unexpected error while getting the method or property create on object ScriptApp.ClockTriggerBuilder. [line: 7, function: myFunction, file: Code] 

Thanks.

ziganotschka
  • 25,866
  • 2
  • 16
  • 33

1 Answers1

0

Is this while testing the add-on? It took me a long time to realise, but setting triggers is not supported in testing add-ons. The only way to test it is manually create the trigger to check that the code works, then publishing the add-on and hope for the best.

Here's a related thread: Google Scripts: Installable Trigger Failing with Test Add-On

Graham
  • 55
  • 3