Add-on not visible in sheet

98 views Asked by At

I'm new to google app script. I have configured my add-on. I cannot open the add-on once the user has already opened it.

Suppose i have opened the add-on. Now I'm again going to open it then it shows the "content not available for this message". I have attached the image. My code is below: Addon Image appscript.json

{
  "timeZone": "America/New_York",
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "oauthScopes": [
    "https://www.googleapis.com/auth/spreadsheets.readonly",
    "https://www.googleapis.com/auth/userinfo.email",
    "https://www.googleapis.com/auth/script.container.ui",
    "https://www.googleapis.com/auth/script.external_request",
    "https://www.googleapis.com/auth/spreadsheets"
  ],
  "addOns": {
    "common": {
      "name": "Test Addon",
      "logoUrl": "https://test/add-on_logo-32x32.png",
      "layoutProperties": {
        "primaryColor": "#2772ed"
      },
      "homepageTrigger": {
        "runFunction": "showSidebar"
      }
    },
    "sheets": {
      "homepageTrigger": {
        "runFunction": "showSidebar"
      }
    }
  },
}

Macro.gs

function onOpen() {
  SpreadsheetApp.getUi()
    .createMenu('Custom Menu')
    .addItem('Show sidebar', 'showSidebar')
    .addToUi();
}

function doGet() {
  return HtmlService.createHtmlOutputFromFile('home');
}

function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename)
    .getContent();
}

function showSidebar() {
    
  var html = HtmlService.createTemplateFromFile('login').evaluate().setTitle("test Add-on")
  SpreadsheetApp.getUi()
    .showSidebar(html);
}

function goToHome(token) {
  const scriptProperties = PropertiesService.getScriptProperties();
  scriptProperties.setProperty('API_TOKEN', token);
  var html = HtmlService.createTemplateFromFile('home').evaluate().setTitle("test Add-on")
  SpreadsheetApp.getUi()
    .showSidebar(html);

}

Can anyone tell me when I have made a mistake?

1

There are 1 answers

2
Steinn E. Sigurðarson On

I believe the addOns key in the manifest (appscript.json), and the associated trigger functions only work with the CardService based UI.

I have built a similar application with a smaller appscript.json (for Slides):

{
  "timeZone": "Etc/UTC",
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "oauthScopes": [
    "https://www.googleapis.com/auth/presentations.currentonly",
    "https://www.googleapis.com/auth/script.container.ui",
    "https://www.googleapis.com/auth/script.external_request"
  ],
  "dependencies": {
  }
}

and the (slightly redacted) Code.gs contents:

function onInstall(e) {
  onOpen(e);
}

function onOpen() {
  SlidesApp.getUi() 
      .createMenu('App')
      .addItem('Open App', 'openApp')
      .addToUi();
}

function openApp(){
  var html = HtmlService.createTemplateFromFile('app'); // open app.html
  var userToken = PropertiesService.getUserProperties().getProperty('USER_TOKEN');
  if(userToken){
    html.token = '?token='+userToken;
  }
  else{
    html.token = '';
  }

  SlidesApp.getUi() 
    .showSidebar(html.evaluate().setTitle('App'));
}

This works fine to open from the menu in Google Slides, but before going this route I also spent a lot of time attempting to use the triggerFunctions and the addOns key in the manifest.