是否找到一种使用库版本的方法? [英] Finding a way to get the Library Version used?

查看:46
本文介绍了是否找到一种使用库版本的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过库在多个电子表格上部署脚本.但是,您可能知道,脚本还没有办法知道它是否正在运行最新版本.

I am deploying a script on multiple spreadsheets via the Libraries. But as you may know, there is no way (yet) for the script to know if it's running the latest version.

我正在尝试通过为自己的代码创建自己的版本控制来解决此问题.我有一个Web服务,提供我的库代码的最新版本号,以便可以对其进行比较,但是onOpen()无法运行fetchURL.我尝试打开一个电子表格来保留信息,但是同样,onOpen()不允许您使用openById ...

I am trying to find a way around this by creating my own versioning for my code. I have a web service giving back the latest version number of my library code so I can compare it, but the onOpen() cannot run fetchURL. I tried opening a spreadsheet that would keep the info, but again the onOpen() do not let you openById...

onOpen()触发器具有安全限制,这使我无法查阅可用于保持版本控制的外部数据源.

onOpen() trigger has security limitations that prevent me to consult an external data source that I could use to keep my versioning.

注意:我不想对onOpen()事件使用脚本触发器.复制电子表格时,不会复制脚本触发器.

Note: I do not want to use script trigger for the onOpen() event. Script trigger are not copied when the spreadsheet is copied.

因此,我对如何通过指向外部数据源(例如url,其他电子表格等)检查onOpen()触发事件上的库版本的想法不多了.

So I am running out of ideas on how to check a library version on a onOpen() trigger event by pointing on an external data source (being a url, other spreadsheet - anything!).

有什么建议吗?

推荐答案

最简单的解决方案是将getVersion()方法添加到您的库中,并在每次更新库时手动对其进行更新.

Simplest solution is to add a getVersion() method to your library and manually update it every time you update the library.

我看到您不仅想知道版本,而且还想知道这是否是最新版本.您可以将该信息存储在库中的ScriptProperties中,并具有如下功能:

Edited: I see you want to know not just the version but whether this is the latest version. You can store that information in ScriptProperties in the library and have a function like this:

function isLatestVersion() {
  return currentVersion == ScriptProperties.getProperty("latestVersion");
}

(我假设您可以将currentVersion硬编码到代码中,并在每次重新部署Web应用程序时进行更改.)可以通过文件">项目属性"菜单来编辑脚本属性,并且可以更改值而无需重新部署脚本,因此通过从该菜单更改latestVersion,您将使旧版本在调用isLatestVersion()时突然开始响应"false".

(I'm assuming you are ok with hardcoding currentVersion into the code and changing it each time you redeploy the webapp.) Script properties can be edited via the File > Project Properties menu, and you can change the value without redeploying the script, so by changing latestVersion from that menu you will make old versions suddenly start responding "false" when calling isLatestVersion().

这篇关于是否找到一种使用库版本的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆