2017-02-23 3 views
1

私はdocsアドオンを持っています。ここでは、onOpen(e)関数でアラートを呼び出すことによって新しいアップデートや機能についてユーザを表示する必要があります。もう一度ボタンを表示しないように、一度だけ一生にDocumentApp.getUi()アラートを1回だけ実行すると新機能が通知されます

OR

重要なポイントと。

どうすればよいですか?

function onOpen(e) { 
    DocumentApp.getUi().createAddonMenu() 
     .addItem('ez-notes', 'Sidebar') 
     .addToUi(); 
    DocumentApp.getUi().alert("new feature..."); //will trouble user everytime. 
} 

答えて

2

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 

} 
1

はこれを行う方法で、この5月にしかし私は、過去のスクリプトでそれを使用サンディのバージョン - より複雑になる:

var ss = SpreadsheetApp.getActiveSpreadsheet(); 
 

 
function onOpen() { 
 
    
 
    var documentProperties = PropertiesService.getDocumentProperties(); 
 
    Utilities.sleep(100) 
 
    var checkOpen = documentProperties.getProperty('checkOpenStatus'); 
 
    Utilities.sleep(100) 
 

 
    
 
    if(checkOpen == "true") { 
 

 
    } 
 
    else { 
 
    newfeature(); 
 
    } 
 
    }; 
 

 
    
 
    function newfeature() { 
 
    var doc = SpreadsheetApp.getActiveSpreadsheet(); 
 
    var app = UiApp.createApplication().setTitle('New feature'); 
 
    var panel = app.createVerticalPanel(); 
 
     
 
    // add the html panel 
 
    app.add(app.createHTML("<b>New features</b><br><br><b>1.</b>New feature text")); 
 
    
 
     // adds checkbox 
 
    var cBox = app.createCheckBox("Do Not show this on Load").setName("chk1").setId("chk1"); 
 
    
 
    // set check box stuff 
 
    var cBoxClick = app.createServerClickHandler('checked'); 
 
    cBoxClick.addCallbackElement(cBox); 
 
    cBox.addClickHandler(cBoxClick); 
 
    app.add(cBox); 
 
    app.add(panel); 
 
    doc.show(app); 
 
    return app; 
 
    
 
    } 
 

 
    function checked(e) { 
 
    var app = UiApp.getActiveApplication(); 
 
    
 
    if (e.parameter.chk1 == "true") 
 
    { 
 
    var documentProperties = PropertiesService.getDocumentProperties(); 
 
    Utilities.sleep(100) 
 
    documentProperties.setProperty('checkOpenStatus', 'true'); 
 
    } 
 
    else 
 
    { 
 
    var documentProperties = PropertiesService.getDocumentProperties(); 
 
    Utilities.sleep(100) 
 
    documentProperties.setProperty('checkOpenStatus', 'false'); 
 
    } 
 
    return app; 
 
    } 
 

 

関連する問題