Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Los complementos del editor publicados pueden crear elementos de menú personalizados en el menú Extensiones de su editor. Puedes insertar un menú de complemento con el método Ui.createAddonMenu() y agregarle elementos con el método Menu.addItem(). Por lo general, los menús se crean en el método onOpen(e) del complemento.
Puedes crear menús dinámicos que cambien según las interacciones del usuario o el estado del complemento. Sin embargo, los complementos deben crear un menú inicial antes de que el usuario los autorice. Por este motivo, debes verificar el modo de autorización del complemento antes de crear menús en onOpen(e). No intentes realizar ninguna acción que requiera autorización (como verificar la secuencia de comandos Properties) mientras el complemento esté en ScriptApp.AuthMode.NONE. Consulta el ciclo de vida de la autorización para obtener más detalles sobre los modos y el ciclo de vida de la autorización.
En el siguiente ejemplo, se muestra cómo compilar un menú de complementos dinámico para diferentes modos de autorización:
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();}
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Falta la información que necesito","missingTheInformationINeed","thumb-down"],["Muy complicado o demasiados pasos","tooComplicatedTooManySteps","thumb-down"],["Desactualizado","outOfDate","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Problema con las muestras o los códigos","samplesCodeIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-07-31 (UTC)"],[[["\u003cp\u003ePublished Editor Add-ons can create custom menu items under the Extensions menu using \u003ccode\u003eUi.createAddonMenu()\u003c/code\u003e and \u003ccode\u003eMenu.addItem()\u003c/code\u003e, typically within the add-on's \u003ccode\u003eonOpen(e)\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eWhile unpublished add-ons can create top-level menus, it's recommended to use \u003ccode\u003eUi.createAddonMenu()\u003c/code\u003e for published add-ons to ensure consistent user experience.\u003c/p\u003e\n"],["\u003cp\u003eAdd-ons must create an initial menu before user authorization and adjust menu items dynamically based on the authorization mode (\u003ccode\u003eScriptApp.AuthMode\u003c/code\u003e) to avoid errors.\u003c/p\u003e\n"],["\u003cp\u003eThe provided example demonstrates building a dynamic add-on menu that adapts to different authorization modes, using \u003ccode\u003eScriptApp.AuthMode.NONE\u003c/code\u003e to control actions requiring authorization.\u003c/p\u003e\n"]]],["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"],null,["Published [Editor add-ons](/workspace/add-ons/concepts/types#editor_add-ons)\ncan create custom menu items under their editor's **Extensions** menu. You can\ninsert an add-on menu by using the\n[`Ui.createAddonMenu()`](/apps-script/reference/base/ui#createAddonMenu()) method\nand add items to it using the\n[`Menu.addItem()`](/apps-script/reference/base/menu#addItem(String,String))\nmethod. Menus are usually created in the add-on's `onOpen(e)` method.\n| **Caution:** Unpublished add-ons can also [create custom top-level menus](/apps-script/guides/menus#custom_menus_in_google_docs_sheets_slides_or_forms), but these are automatically moved under the **add-ons** menu if the add-on is published and may not result in the user experience you intended. If you intend to publish the add-on, always use [`Ui.createAddonMenu()`](/apps-script/reference/base/ui#createAddonMenu()) to define the add-on menu.\n\nYou can create dynamic menus that change based on user interactions or add-on\nstate. However, add-ons must create an initial menu *before* the add-on is\nauthorized by the user. Because of this, you must check the add-on's\n[authorization mode](/workspace/add-ons/concepts/editor-auth-lifecycle#authorization_modes)\nprior to constructing menus in `onOpen(e)`. Do not attempt to take any action\nthat requires authorization (such as checking the script\n[`Properties`](/apps-script/reference/properties))\nwhile the add-on is in `ScriptApp.AuthMode.NONE`. See the\n[authorization lifecycle](/workspace/add-ons/concepts/editor-auth-lifecycle#the_complete_lifecycle)\nfor more details on the authorization modes and lifecycle.\n| **Warning:** If you attempt to take actions that require authorization when the authorization mode is `ScriptApp.AuthMode.NONE`, it results in an error. This may prevent your add-on menus from being displayed.\n\nThe following example shows how to build a dynamic add-on menu for different\nauthorization modes: \n\n function onOpen(e) {\n var menu = SpreadsheetApp.getUi().createAddonMenu(); // Or DocumentApp or SlidesApp or FormApp.\n if (e && e.authMode == ScriptApp.AuthMode.NONE) {\n // Add a normal menu item (works in all authorization modes).\n menu.addItem('Start workflow', 'startWorkflow');\n } else {\n // Add a menu item based on properties (doesn't work in AuthMode.NONE).\n var properties = PropertiesService.getDocumentProperties();\n var workflowStarted = properties.getProperty('workflowStarted');\n if (workflowStarted) {\n menu.addItem('Check workflow status', 'checkWorkflow');\n } else {\n menu.addItem('Start workflow', 'startWorkflow');\n }\n // Record analytics.\n UrlFetchApp.fetch('http://www.example.com/analytics?event=open');\n }\n menu.addToUi();\n }"]]