0

I am trying to get started with a "Hello World" implementation of a menu that loads a sidebar for a Google Workspace Add-On for Google Sheets.

When I open a new Google Sheet, I expect to see a menu appear under Extensions > MyApp > Start. And when I click the item labeled "Start" in the dropdown menu, I expect to see a sidebar open on the right that reads "Hello World."

Instead of that, what I actually see is when I open a new Google Sheet, I see no MyApp item in the Extensions dropdown menu. It's as if my test deployment was never loaded.

The below code is contained in a standalone script file (as required to make a Workspace Add-on).

In addition to the code I shared below, I also followed the documentation at this link and did the following steps necessary to create a test deployment.

What am I missing or doing wrong?

https://developers.google.com/apps-script/add-ons/cats-quickstart#drive.gs

Create the Apps Script project

  1. To create a new Apps Script project, go to script.new. Click Untitled project.
  2. Rename the Apps Script project Cats and click Rename.
  3. Next to the Code.gs file, click More more_vert > Rename.
  4. Name the file Common. Click Add a file add > Script.
  5. Name the file Gmail.
  6. Repeat step 5 to create 2 more script files named Calendar and Drive. When you're done you should have 4 separate script files.
  7. Click Project Settings The icon for project settings.
  8. Check the Show "appsscript.json" manifest file in editor box.
  9. Click Editor code. 10.Open the appsscript.json file and replace the contents with the following code, then click Save Save icon.

Copy the Cloud project number

  1. Go to your Cloud project in the Google Cloud console.
  2. Click Settings and Utilities more_vert > Project settings.
  3. Copy the Project number.

Set the Apps Script project's Cloud project

  1. In your Apps Script project, click Project Settings The icon for project settings.
  2. Under Google Cloud Platform (GCP) Project, click Change project.
  3. In GCP project number, paste the Google Cloud project number.
  4. Click Set project.

Install a test deployment

  1. In your Apps Script project, click Editor code.
  2. Open the Common.gs file and click Run. When prompted, authorize the script.
  3. Click Deploy > Test deployments.
  4. Click Install > Done.
Code.js
const ss = SpreadsheetApp.getActiveSpreadsheet();

function onOpen( e ) {
  ui.createAddonMenu()
    .addItem( 'Start', 'showSidebar', )
    .addToUi();
  
  const menuItems = [];
  menuItems.push({ name: 'Start' , functionName: 'showSidebar' });
  ss.addMenu( 'MyApp', menuItems, );
}

function showSidebar() {
  // code TBD
  // right now, I'm just trying to get the menu to appear
}
Sidebar.html
<html>
  <body>
    <div>Hello World</div>
  </body>
</html>
appsscript.json

{
  "timeZone":"America/Los_Angeles",
  "dependencies":{
    
  },
  "exceptionLogging":"STACKDRIVER",
  "runtimeVersion":"V8",
  "addOns":{
    "calendar":{
      "createSettingsUrlFunction":"getConferenceSettingsPageUrl",
      "conferenceSolution":[
        {
          "id":"my-video-conf",
          "logoUrl":"https://lh3.googleusercontent.com/...",
          "name":"My Video Conference",
          "onCreateFunction":"onCreateMyVideoConference"
        },
        {
          "id":"my-streamed-conf",
          "logoUrl":"https://lh3.googleusercontent.com/...",
          "name":"My Streamed Conference",
          "onCreateFunction":"onCreateMyStreamedConference"
        }
      ],
      "currentEventAccess":"READ_WRITE",
      "eventOpenTrigger":{
        "runFunction":"onCalendarEventOpen"
      },
      "eventUpdateTrigger":{
        "runFunction":"onCalendarEventUpdate"
      },
      "eventAttachmentTrigger":{
        "label":"My Event Attachment",
        "runFunction":"onCalendarEventAddAttachment"
      },
      "homepageTrigger":{
        "runFunction":"onCalendarHomePageOpen",
        "enabled":true
      }
    },
    "common":{
      "homepageTrigger":{
        "runFunction":"onDefaultHomePageOpen",
        "enabled":true
      },
      "layoutProperties":{
        "primaryColor":"#ff392b",
        "secondaryColor":"#d68617"
      },
      "logoUrl":"https://ssl.gstatic.com/docs/script/images/logo/script-64.png",
      "name":"Demo Google Workspace Add-on",
      "openLinkUrlPrefixes":[
        "https://mail.google.com/",
        "https://script.google.com/a/google.com/d/",
        "https://drive.google.com/a/google.com/file/d/",
        "https://en.wikipedia.org/wiki/",
        "https://www.example.com/"
      ],
      "universalActions":[
        {
          "label":"Open settings",
          "runFunction":"getSettingsCard"
        },
        {
          "label":"Open Help URL",
          "openLink":"https://www.example.com/help"
        }
      ],
      "useLocaleFromApp":true
    },
    "drive":{
      "homepageTrigger":{
        "runFunction":"onDriveHomePageOpen",
        "enabled":true
      },
      "onItemsSelectedTrigger":{
        "runFunction":"onDriveItemsSelected"
      }
    },
    "gmail":{
      "composeTrigger":{
        "selectActions":[
          {
            "text":"Add images to email",
            "runFunction":"getInsertImageComposeCards"
          }
        ],
        "draftAccess":"METADATA"
      },
      "contextualTriggers":[
        {
          "unconditional":{
            
          },
          "onTriggerFunction":"onGmailMessageOpen"
        }
      ]
    },
    "docs":{
      "homepageTrigger":{
        "runFunction":"onEditorsHomepage"
      },
      "onFileScopeGrantedTrigger":{
        "runFunction":"onFileScopeGrantedEditors"
      }
    },
    "sheets":{
      "homepageTrigger":{
        "runFunction":"onOpen"
      },
      "onFileScopeGrantedTrigger":{
        "runFunction":"onFileScopeGrantedEditors"
      }
    },
    "slides":{
      "homepageTrigger":{
        "runFunction":"onEditorsHomepage"
      },
      "onFileScopeGrantedTrigger":{
        "runFunction":"onFileScopeGrantedEditors"
      }
    }
  }
}

Rubén
  • 34,714
  • 9
  • 70
  • 166
Let Me Tink About It
  • 15,156
  • 21
  • 98
  • 207

1 Answers1

3

From the question:

When I open a new Google Sheet, I expect to see a menu appear under Extensions > MyApp > Start.

This is not possible with Google Workspace Add-ons. For this you should create an Editor Add-on.

Resources

Related

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • I am trying to get a menu to appear so I can show the sidebar. [As shown in this video.](https://youtu.be/hj3y0QTykdQ?t=61) ([The documentation is thin.](https://www.google.com/search?client=firefox-b-1-d&q=how+do+i+get+the+google+workspace+menu+to+appear+from+google+sheets)) What is the secret to getting the menu in the right margin to show? – Let Me Tink About It Jan 25 '23 at 03:43
  • 1
    It looks that you are trying to take a shorcut but instead you are jumping around... What is the problem with the official docs? – Rubén Jan 25 '23 at 03:48
  • 1
    This is Workspace Add-on quickstart -> https://developers.google.com/apps-script/add-ons/cats-quickstart – Rubén Jan 25 '23 at 03:51
  • 1
    This is a Workspace Add-on sample for Google Sheets -> https://developers.google.com/apps-script/add-ons/share-macro – Rubén Jan 25 '23 at 03:52
  • 1
    Thank you so much for this last quikstart link. I already followed the first quickstart and it worked great. The only problem with it is it doesn't deal with Google Sheets. I didn't see the last one because the title mentions Macros but doesn't say anything about Google Sheets. That was the key piece of information I was looking for. So, I sincerely and gratefully appreciate you for that. – Let Me Tink About It Jan 25 '23 at 04:35