Google apps script 仅运行一次DocumentApp.getUi()警报以通知新功能
我有一个docs插件,在那里我需要通过调用onOpen(e)函数中的警报来向用户显示其新的更新和功能。重要的一点是,一生只有一次 或 就像“不再显示”按钮一样 我该怎么做Google apps script 仅运行一次DocumentApp.getUi()警报以通知新功能,google-apps-script,google-docs-api,add-on,Google Apps Script,Google Docs Api,Add On,我有一个docs插件,在那里我需要通过调用onOpen(e)函数中的警报来向用户显示其新的更新和功能。重要的一点是,一生只有一次 或 就像“不再显示”按钮一样 我该怎么做 function onOpen(e) { DocumentApp.getUi().createAddonMenu() .addItem('ez-notes', 'Sidebar') .addToUi(); DocumentApp.getUi().alert("new featur
function onOpen(e) {
DocumentApp.getUi().createAddonMenu()
.addItem('ez-notes', 'Sidebar')
.addToUi();
DocumentApp.getUi().alert("new feature..."); //will trouble user everytime.
}
有一个名为
onInstall()的保留函数名
它用于附加组件。它仅在安装加载项时运行
function onInstall() {}
每当发布外接程序的新版本时,此操作都不会运行。如果希望某些代码在每个新发布的版本中只运行一次,则需要存储用户在某处使用的当前版本和最后版本,然后在某些代码运行时比较它们。您可以将版本号保存在“属性服务”、“脚本属性”或“硬编码”中的当前版本号中。每次运行oOpen()函数时,都需要运行一些服务器代码,将当前版本与用户使用的上一个已知保存版本进行比较
我有一个函数,它只返回当前最新版本应该是什么,并且每当发布新版本时,我都会更改该数字:
function newestVersion() {return "12";}// Return the newest version number
function onOpen() {
var newestVersion,lastUsedVersion;
newestVersion = newestVersion();//Call function to get the newest version
lastUsedVersion = fncGetLastUsedVersion();//Run function to get last used version
if (lastUsedVersion !== newestVersion) {
//Display message
//Save new value of Last Used Version to User or Document Properties
}
}
function lastUsedVersion() {
//Get last used version from User or Document Properties
}
这里有一种方法可以做到这一点,这可能比Sandy的版本更复杂-但是我在过去的脚本中使用了它:
var ss=SpreadsheetApp.getActiveSpreadsheet();
函数onOpen(){
var documentProperties=PropertiesService.getDocumentProperties();
公用设施.睡眠(100)
var checkOpen=documentProperties.getProperty('checkOpenStatus');
公用设施.睡眠(100)
如果(checkOpen==“true”){
}
否则{
newfeature();
}
};
函数newfeature(){
var doc=SpreadsheetApp.getActiveSpreadsheet();
var app=UiApp.createApplication().setTitle(“新功能”);
var panel=app.createVerticalPanel();
//添加html面板
app.add(app.createHTML(“新功能
1.New功能文本”);
//添加复选框
var cBox=app.createCheckBox(“加载时不显示”).setName(“chk1”).setId(“chk1”);
//设置复选框内容
var cBoxClick=app.createServerClickHandler('checked');
cBoxClick.addCallbackElement(cBox);
addClickHandler(cBoxClick);
应用程序添加(cBox);
应用程序添加(面板);
文件显示(应用程序);
返回应用程序;
}
功能检查(e){
var app=UiApp.getActiveApplication();
如果(e.parameter.chk1==“true”)
{
var documentProperties=PropertiesService.getDocumentProperties();
公用设施.睡眠(100)
setProperty('checkOpenStatus','true');
}
其他的
{
var documentProperties=PropertiesService.getDocumentProperties();
公用设施.睡眠(100)
setProperty('checkOpenStatus','false');
}
返回应用程序;
}