How to use versioned deployments when programmatically creating triggers?

我只是一个虾纸丫 提交于 2019-12-06 10:59:52
  1. You want to know that when a trigger is installed by ScriptApp.newTrigger(), which version of script is used.
  2. You want to know the method for installing a trigger by selecting version of script.

I understand your question like above. If my understanding is correct, how about this answer? Please think of this as one of several answers.

Answer for Q1:

  • When a trigger is installed by ScriptApp.newTrigger(), although the value of "Deployment" is not shown in "Current project's triggers", the latest script is run by the installed trigger. This situation is independent of the version of script. The current latest script is used.

  • If the trigger is manually installed, you can select the deployment version at "Choose which deployment should run".

    • Unfortunately, in the current stage, this cannot be achieved by the script yet. I think that this might be achieved by the future update.

Answer for Q2:

In order to install a trigger by selecting version of script, as a workaround, I would like to propose to use a library. The flow of this workaround is as follows. This is a sample flow.

  1. Create 2 standalone projects.
    • One is used as a library.
    • Another is used as the project to use the library.
  2. In the project to use the library, for example, function myFunction() {lib.myFunction()} is put. This script runs the function of the library.
    • Install the library to this project.
    • You can select the script, that you want to make users run, by selecting the version of library.
    • Trigger is installed to this project.
  3. The project of the library is the project for developing. It manages the version of developing script by "Manage version" of the script editor.
  4. When the trigger is installed, it runs ScriptApp.newTrigger("myFunction") in the project to use the library. At this time, when the trigger is run, the selected version of library is used. By this, the latest script of library is not used. Users can use the stable script of the version you selected.
Note:
  • You can also see the version of library at Manifests file (appsscript.json). This file can be modified by the script. By this, you can also modify the version of script using by the trigger by the script.

References:

If I misunderstand your question, I'm sorry.

Yes, it always point to the "head" as versioned deployments are only available for Gmail Add-ons.

The above is based on that the only the guide to publish a Gmail add-on includes as step the creation of a versioned deployment -> https://developers.google.com/gmail/add-ons/how-tos/publish#step_1_create_a_versioned_deployment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!