I am building a Google Workspace add-on for Google Sheets and I'm trying to show a dialog using a card built by the CardService
but I get the following error message.
TypeError: Cannot read properties of undefined (reading 'newCardHeader')
It appears the CardService
object is undefined
?
What am I doing wrong?
Code.gs
const ui = SpreadsheetApp.getUi();
const onOpen = e => {
ui.createAddonMenu()
.addItem( 'Help', 'showHelp', )
.addToUi();
}
const buildCard = () => {
const header = CardService.newCardHeader()
.setTitle( "CardTitle", );
const card = CardService.newCardBuilder()
.setHeader( header, )
.build();
return card;
}
const showHelp = () => {
const card = buildCard();
ui.showDialog( card, );
}