I have a Google Workspace Add-on, I want to update the sidebar card everytime there's a new sheet. Below is my code:
function onHomepage() {
createOnChangeTrigger();
return greetCard('hello');
}
function createOnChangeTrigger() {
const triggers = ScriptApp.getUserTriggers(SpreadsheetApp.getActiveSpreadsheet());
if (triggers.length > 0) {
return;
}
ScriptApp.newTrigger('myOnChange')
.forSpreadsheet(SpreadsheetApp.getActive())
.onChange()
.create();
}
function myOnChange() {
const card = greetCard('hi');
const newcard = CardService.newNavigation()
.popToRoot()
.pushCard(card);
return CardService.newActionResponseBuilder()
.setNavigation(newcard)
.build();
}
function greetCard(text) {
Logger.log('greet: %s', text)
let content = CardService.newDecoratedText().setText(text);
let section = CardService.newCardSection().addWidget(content);
return CardService.newCardBuilder()
.addSection(section)
.build();
}
I conclude that this isn't possible because the trigger functions are invoked from the server.