Please try this example
function showCard() {
var card = CardService.newCardBuilder()
.addSection(CardService.newCardSection()
.addWidget(CardService.newTextParagraph().setText('This is the top of the card.'))
.addWidget(CardService.newTextInput().setTitle('Input 1')))
.addSection(CardService.newCardSection()
.addWidget(CardService.newTextInput().setTitle('Input 2')))
.addSection(CardService.newCardSection()
.addWidget(CardService.newTextInput().setTitle('Input 3')))
.build();
var navigation = CardService.newNavigation().popToRoot().pushCard(card);
return CardService.newActionResponseBuilder()
.setNavigation(navigation)
.build();
}
function scrollToWidget() {
var widget = CardService.newTextInput().setTitle('Input 3');
var card = CardService.newCardBuilder().addWidget(widget).build();
var navigation = CardService.newNavigation().pushCard(card);
var actionResponseBuilder = CardService.newActionResponseBuilder()
.setNavigation(navigation);
actionResponseBuilder
.setStateChanged(true)
.setNotification(CardService.newNotification().setText('Widget is now visible'));
return actionResponseBuilder.build();
}
function onGmailMessage(e) {
var card = CardService.newCardBuilder()
.addSection(CardService.newCardSection()
.addWidget(CardService.newTextParagraph().setText('This is a Gmail Add-on')))
.addSection(CardService.newCardSection()
.addWidget(CardService.newButton()
.setText('Show card')
.setOnClickAction(CardService.newAction()
.setFunctionName('showCard'))))
.build();
var notification = CardService.newNotification()
.setText('New message detected!');
var universalActionResponseBuilder = CardService.newUniversalActionResponseBuilder()
.displayAddOnCards([card])
.setNotification(notification);
return universalActionResponseBuilder.build();
}
This code creates a Gmail add-on that displays a card with a button that shows another card when clicked. The showCard() function creates the initial card, while the scrollToWidget() function creates a new card with a specific widget and ensures that the widget is visible by using ensureWidgetVisible().
I hope this helps clarify things.