5

I am creating a Gmail Add-on. The following reference page says - https://developers.google.com/gmail/add-ons/reference/

"Gmail add-ons are built using Apps Script and the many services it provides. You can use any of the Apps Script services when building your add-on"

Basically, I want to have the small screen to pop up on clicking a button in my Gmail add-on.

As of now I have added a button in my section as follows and tied it to an action handler 'htmltest':-

var htmlTest = CardService.newAction().setFunctionName('htmlTest');
var button = CardService.newTextButton().setText("htmlTest").setOnClickAction(htmlTest);
section.addWidget(button);

This is how htmlTest looks like:-

function htmlTest(e){
return HtmlService.createHtmlOutputFromFile('doubleCheck');
}

And this is the doubleCheck.html file I want it to pop up:-

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    Hello, World!
  </body>
</html>

But when I click the button it gives a run-time error:- Missing required fields in markup:

Any clues how to use HtmlService while creating Gmail

Manikandan C
  • 668
  • 1
  • 9
  • 22
Shubham Gupta
  • 159
  • 1
  • 14
  • 2
    I don't think HTMLService is available for Gmail add-ons.. We are required to use CardService instead.. https://developers.google.com/apps-script/reference/card-service/ Please correct me if I am wrong.. –  Nov 28 '17 at 14:27
  • Its written here(https://developers.google.com/gmail/add-ons/reference/) that "You can use any of the Apps Script services when building your add-on, but the following are often particularly useful: are cardService, PropertiesService etc..." – Shubham Gupta Nov 29 '17 at 08:29
  • 2
    hmm... anyway, for what it's worth, CardService has a facility for popups as well... refer https://developers.google.com/gmail/add-ons/reference/card-service/open-link –  Nov 30 '17 at 06:02
  • Cool. If that works, it would be helpful – Shubham Gupta Dec 01 '17 at 19:16
  • Possible duplicate of [google script use html service in gmail addon](https://stackoverflow.com/q/48636518/11683) – GSerg Apr 11 '20 at 20:22

2 Answers2

2

In the overview section of the CardService, It quotes:

“Currently you can only use this service to construct Gmail add-ons.“

So HtmlService is not available in constructing Gmail addon’s currently.

https://developers.google.com/apps-script/reference/card-service/

Ronnie Headen
  • 289
  • 1
  • 13
2

TL;DR:

To build interfaces for Gmail add-ons, you must use the Card service instead [of the HTML Service].

Quoted from your reference, under HTML service.

For popups, +1 to @akshay who recommended OVERLAY: CardService.newOpenLink().setOpenAs(CardService.OpenAs.OVERLAY), which will "Open as an overlay such as a pop-up". See CardService OpenAs.

Hibuki
  • 544
  • 3
  • 14