Add-on editor yang dipublikasikan
dapat membuat item menu kustom di menu Ekstensi editor. Anda dapat
menyisipkan menu add-on menggunakan
metode Ui.createAddonMenu()
dan menambahkan item ke dalamnya menggunakan
metode Menu.addItem(). Menu biasanya dibuat dalam metode onOpen(e) add-on.
Anda dapat membuat menu dinamis yang berubah berdasarkan interaksi pengguna atau status
add-on. Namun, add-on harus membuat menu awal sebelum add-on
diberi otorisasi oleh pengguna. Oleh karena itu, Anda harus memeriksa
mode otorisasi
add-on sebelum membuat menu di onOpen(e). Jangan mencoba melakukan tindakan apa pun
yang memerlukan otorisasi (seperti memeriksa skrip
Properties)
saat add-on berada di ScriptApp.AuthMode.NONE. Lihat
siklus proses otorisasi
untuk mengetahui detail selengkapnya tentang mode dan siklus proses otorisasi.
Contoh berikut menunjukkan cara mem-build menu add-on dinamis untuk berbagai
mode otorisasi:
functiononOpen(e){varmenu=SpreadsheetApp.getUi().createAddonMenu();//OrDocumentApporSlidesApporFormApp.if(e && e.authMode==ScriptApp.AuthMode.NONE){//Addanormalmenuitem(worksinallauthorizationmodes).menu.addItem('Start workflow','startWorkflow');}else{//Addamenuitembasedonproperties(doesn't work in AuthMode.NONE).varproperties=PropertiesService.getDocumentProperties();varworkflowStarted=properties.getProperty('workflowStarted');if(workflowStarted){menu.addItem('Check workflow status','checkWorkflow');}else{menu.addItem('Start workflow','startWorkflow');}//Recordanalytics.UrlFetchApp.fetch('http://www.example.com/analytics?event=open');}menu.addToUi();}
[null,null,["Terakhir diperbarui pada 2024-12-18 UTC."],[[["Published Editor Add-ons can create custom menu items under the Extensions menu using `Ui.createAddonMenu()` and `Menu.addItem()`, typically within the add-on's `onOpen(e)` method."],["While unpublished add-ons can create top-level menus, it's recommended to use `Ui.createAddonMenu()` for published add-ons to ensure consistent user experience."],["Add-ons must create an initial menu before user authorization and adjust menu items dynamically based on the authorization mode (`ScriptApp.AuthMode`) to avoid errors."],["The provided example demonstrates building a dynamic add-on menu that adapts to different authorization modes, using `ScriptApp.AuthMode.NONE` to control actions requiring authorization."]]],["Editor add-ons create custom menu items under the **Extensions** menu using `Ui.createAddonMenu()` and `Menu.addItem()`, typically within the `onOpen(e)` method. Menus must be defined *before* user authorization, necessitating a check of the add-on's authorization mode. Dynamic menus can change based on user interactions. Actions requiring authorization should not be performed when `AuthMode.NONE`. The provided example shows a dynamic menu construction for different modes, adding either \"Start workflow\" or \"Check workflow status\".\n"]]