Reputation: 3423
I have a Card object in a GmailApp with some widgets. I want to clear the card after pressing a button.
How can I do that?
Upvotes: 0
Views: 336
Reputation: 419
You can do this by updating an empty card in the current navigation in the callback of the button action. Follow the below piece of code:
function getCard() {
var cb = CardService.newCardBuilder();
cb.setHeader(CardService.newCardHeader().setTitle("Card Header"));
var section = CardService.newCardSection();
var submitForm = CardService.newAction().setFunctionName('clearCard');
var submitButton = CardService.newTextButton().setText('Clear Card').setOnClickAction(submitForm);
section.addWidget(submitButton);
cb.addSection(section);
return cb.build();
}
function clearCard(e) {
var navigation = CardService.newNavigation().updateCard(emptyCard());
return CardService.newActionResponseBuilder().setNavigation(navigation).build();
}
function getEmptyWidget() {
return CardService.newKeyValue().setContent("");
}
function getEmptySection() {
return CardService.newCardSection().addWidget(getEmptyWidget());
}
function emptyCard() {
var cb = CardService.newCardBuilder();
cb.setHeader(CardService.newCardHeader().setTitle("Card Header"));
cb.addSection(getEmptySection());
return cb.build();
}
Upvotes: 1