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.
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() trigger has security limitations that prevent me to consult an external data source that I could use to keep my versioning.
Note: I do not want to use script trigger for the onOpen() event. Script trigger are not copied when the spreadsheet is copied.
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!).
Any suggestions?
Simplest solution is to add a getVersion() method to your library and manually update it every time you update the library.
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");
}
(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().