0

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();
}
Rubén
  • 34,714
  • 9
  • 70
  • 166
paolooo
  • 4,133
  • 2
  • 18
  • 33
  • I conclude that this isn't possible because the trigger functions are invoked from the server. – paolooo Nov 06 '22 at 04:20
  • Hi there @NinoPaolo! Could you please clarify why you need this? I want to see if there is any other approach for reaching your end goal. – Jacques-Guzel Heron Nov 07 '22 at 14:35
  • Hi @Jacques-GuzelHeron, thanks for your comment. What I actually want is, in a spreadsheet, when a user adds a new sheet (e.g. Sheet2, Sheet3), I want the sheet lists in the sidebar (card) add-on to get updated. – paolooo Nov 07 '22 at 23:06

1 Answers1

0

I conclude that this isn't possible because the trigger functions are invoked from the server.

paolooo
  • 4,133
  • 2
  • 18
  • 33