Class CardAction Stay organized with collections Save and categorize content based on your preferences.
Page Summary
CardAction is a clickable menu item added to the card header menu.
CardAction objects can be configured to perform various actions when clicked, including opening authorization flows, composing emails, executing defined actions, or opening URLs.
A CardAction can only have one click action type set at a time.
The text displayed in the card header menu for the CardAction is set using the
setText()method.
A clickable menu item that is added to the card header menu.
constaction=CardService.newAction();// Finish building the action...constcardAction=CardService.newCardAction().setText('Card action').setOnClickAction(action);
Methods
| Method | Return type | Brief description |
|---|---|---|
set | Card | Sets an authorization action that opens a URL to the authorization flow when the object isclicked. |
set | Card | Sets an action that composes a draft email when the object is clicked. |
set | Card | Sets an action that executes when the object is clicked. |
set | Card | Sets an action that opens a URL in a tab when the object is clicked. |
set | Card | Sets a URL to be opened when the object is clicked. |
set | Card | Sets the menu text for this action. |
Detailed documentation
setAuthorizationAction(action)
Sets an authorization action that opens a URL to the authorization flow when the object isclicked. This opens the URL in a new window. When the user finishes the authorization flow andreturns to the application, the add-on reloads.
A UI object can only have one ofset,set,set,set, orset set.
// ...constaction=CardService.newAuthorizationAction().setAuthorizationUrl('url');CardService.newTextButton().setText('Authorize').setAuthorizationAction(action);
Parameters
| Name | Type | Description |
|---|---|---|
action | Authorization | The object that specifies the authorization action to take when this element is clicked. |
Return
Card — This object, for chaining.
setComposeAction(action, composedEmailType)
Sets an action that composes a draft email when the object is clicked. A UI object can onlyhave one ofset,set,set,set, orset set.
TheAction parameter must specify a callback function that returns aCompose object configured usingCompose.
Note: This method doesn't set acompose action that isused toextend the compose UI.Rather, this method connects this UI element to anAction thatcomposes draft messages in Apps Script that areopened in Gmail when the action completes.
// ...constaction=CardService.newAction().setFunctionName('composeEmailCallback');CardService.newTextButton().setText('Compose Email').setComposeAction(action,CardService.ComposedEmailType.REPLY_AS_DRAFT);// ...functioncomposeEmailCallback(e){constthread=GmailApp.getThreadById(e.threadId);constdraft=thread.createDraftReply('This is a reply');returnCardService.newComposeActionResponseBuilder().setGmailDraft(draft).build();}
Parameters
| Name | Type | Description |
|---|---|---|
action | Action | The object that specifies the compose action to take when this element is clicked. |
composed | Composed | An enum value that specifies whether the composed draft is a standalone or reply draft. |
Return
Card — This object, for chaining.
setOnClickAction(action)
Sets an action that executes when the object is clicked. A UI object can only have one ofset,set,set,set, orset set.
TheAction parameter must specify a callback function that returns aAction object.
// ...constaction=CardService.newAction().setFunctionName('notificationCallback');CardService.newTextButton().setText('Create notification').setOnClickAction(action);// ...functionnotificationCallback(){returnCardService.newActionResponseBuilder().setNotification(CardService.newNotification().setText('Some info to display to user'),).build();}
Parameters
| Name | Type | Description |
|---|---|---|
action | Action | The action to take when this element is clicked. |
Return
Card — This object, for chaining.
setOnClickOpenLinkAction(action)
Sets an action that opens a URL in a tab when the object is clicked. Use this function when theURL needs to be built or when you need to take other actions in addition to creating theOpen object. A UI object can only have one ofset,set,set,set, orset set.
TheAction parameter must specify a callback function that returns aAction object configured usingAction.
// ...constaction=CardService.newAction().setFunctionName('openLinkCallback');CardService.newTextButton().setText('Open Link').setOnClickOpenLinkAction(action);// ...functionopenLinkCallback(){returnCardService.newActionResponseBuilder().setOpenLink(CardService.newOpenLink().setUrl('https://www.google.com')).build();}
Parameters
| Name | Type | Description |
|---|---|---|
action | Action | The object that specifies the open link action to take when this element is clicked. |
Return
Card — This object, for chaining.
setOpenLink(openLink)
Sets a URL to be opened when the object is clicked. Use this function when the URL is alreadyknown and only needs to be opened. A UI object can only have one ofset,set,set,set,orset set.
Parameters
| Name | Type | Description |
|---|---|---|
open | Open | AnOpen object describing the URL to open. |
Return
Card — This object, for chaining.
setText(text)
Sets the menu text for this action.
Parameters
| Name | Type | Description |
|---|---|---|
text | String | The menu item text. |
Return
Card — This object, for chaining.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-03 UTC.