google-apps-scriptgoogle-workspace-add-ons

Installable Triggers for workspace Addon


I've been playing around with google scriptapp for a while and even created a test deployment for the cards I built.

I'm wandering if it's possible to create installable triggers for users, using scriptApp.newTrigger() method. How would users install this Trigger when they install my Addon? How do I test it using the test deployment method?

I have tried creating this trigger programmatically. However, since I didn't know how to install it I tested it by running it in the appscript terminal.

I expect that the function with the trigger gets registered when the user installs my addon. How do I go about this?


Solution

  • I have found the perfect solution to my problem. Since Installable triggers need to be installed once, I found universalActions a very suitable use case.

    For instance, this code below will attach a universalAction that'll install the trigger once the user clicks on it.

    "universalActions": [
        {
          "label": "Invoice Reminder",
          "runFunction": "createTrigger"
        }
      ]
    

    Image with universal action