google-workspace-add-ons

Google Workspace Add-On addOns.common.homepageTrigger will not trigger a second time


I have an add-on which utilizes the addOns.common.homepageTrigger function to show a sidebar (https://developers.google.com/apps-script/add-ons/concepts/homepages)

If the user clicks the add-on button in the quick access panel it works just fine, however if they close the sidebar and then click the button in the quick access panel again, a placeholder page appears but nothing else happens:

enter image description here

{
  "timeZone": "Australia/Sydney",
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "dependencies": {
    "enabledAdvancedServices": [
      {
        "userSymbol": "Drive",
        "serviceId": "drive",
        "version": "v2"
      }
    ]
  },
  "oauthScopes": [
    "https://www.googleapis.com/auth/script.scriptapp",
    "https://www.googleapis.com/auth/documents.currentonly",
    "https://www.googleapis.com/auth/spreadsheets",
    "https://www.googleapis.com/auth/presentations",
    "https://www.googleapis.com/auth/script.container.ui",
    "https://www.googleapis.com/auth/drive",
    "https://www.googleapis.com/auth/drive.apps.readonly",
    "https://www.googleapis.com/auth/script.external_request",
    "https://www.googleapis.com/auth/script.locale",
    "https://www.googleapis.com/auth/userinfo.email"
  ],
  "urlFetchWhitelist": [
    "https://cm234-wgs-1.icognition.cloud/",
    "https://docs.google.com/feeds/download/documents/export/Export",
    "https://docs.google.com/spreadsheets/export",
    "https://docs.google.com/feeds/download/presentations/Export"
  ],
  "addOns": {
    "common": {
      "name": "Ingress Records",
      "logoUrl": "https://hydrakubernetes.icognition.cloud/images/ingress_icon_black_40.png",
      "homepageTrigger": {
        "runFunction": "showSidebar",
        "enabled": true
      }
    },
    "sheets": {},
    "docs": {},
    "slides": {}
  }
}
function showSidebar() {
  var sidebarName = "sidebar";

  if (getRecordUri() !== 0) {
    sidebarName = "existing_record_sidebar";
  }

  var ui =
    HtmlService.createHtmlOutputFromFile(sidebarName).setTitle(
      "Ingress Records",
    );

  getUi().showSidebar(ui);
}

Solution

  • The error Content not available for this message is because of the Class HtmlService in the script, and as per Restrictions:

    Google Workspace Add-ons must use card-based interfaces. The HTML/CSS interfaces supported by Editor Add-ons can't be used. Google Workspace Add-ons use a widget-based approach to building user interfaces. This lets the add-on work well on desktop and mobile platforms without requiring you to build an interface for each.

    Instead, use Card Service, and this sample script is how you can create the second sidebar from your other Stack Overflow post.

    function showSidebar() {
      return CardService.newCardBuilder()
        .setHeader(CardService.newCardHeader()
          .setTitle("")
          .setSubtitle("All fields are mandatory, unless indicated as optional."))
        .addSection(CardService.newCardSection().setHeader("Record Type")
          .addWidget(CardService.newSelectionInput()
            .setType(CardService.SelectionInputType.DROPDOWN)
            .setTitle("")
            .setFieldName("RECORD TYPE")
            .addItem("Option 1", "option_1", false)
            .setOnChangeAction(CardService.newAction().setFunctionName("myFunction")))
          .addWidget(CardService.newTextButton()
            .setText("Create record")
            .setTextButtonStyle(CardService.TextButtonStyle.FILLED)
            .setOnClickAction(CardService.newAction().setFunctionName("myFunction"))))
        .build();
    }
    

    OUTPUT

    image