Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

227
Visualizações
Google Apps Scripts: Confused about how to Update Cards

How do you update the data in PropertiesService and show it in another Card?

The data always seems stale, or the card/UI is stale.

For example...

  1. Set up a project for Google Calendar. Run the buildInitState function to initialize it
// appsscript.json
// set the trigger to build the home
....
....
 "addOns": {
    "calendar": {
      "homepageTrigger": {
        "enabled": true,
        "runFunction": "buildInitState"
      }
    },
    "common": {
      ....
....
  1. Initialize function to build the home card
const userStore = PropertiesService.getUserProperties();

// setup userStore and add default values for date 
userStore.setProperties({
  date: (new Date()).getTime(),
});

const showSettingsPageAction =
  CardService.newAction().setFunctionName('showSettingsPage');

const handleDateChangeAction =
  CardService.newAction().setFunctionName('handleDateChange');

function handleDateChange(e) {
  //change the date to what user selects
  const newDate = (new Date(e.formInput.date_field.msSinceEpoch)).getTime();
  userStore.setProperty('date', newDate);
}

// Homepage card
function buildInitState(e) {
  const mainCard = CardService.newCardBuilder();

  // add a date picker
  const DatePicker = CardService.newDatePicker()
    .setTitle('set date')
    .setFieldName('date_field')
    .setValueInMsSinceEpoch((new Date()).getTime())
    .setOnChangeAction(
      CardService.newAction().setFunctionName('handleDateChangeAction')
    );

  // add a button to nav to another card
  const ButtonFindSlots = CardService.newTextButton()
    .setText('NAV TO SETTINGS CARD')
    .setOnClickAction(showSettingsPageAction);

  mainCard
  .addSection(DatePicker)
  .addSection(ButtonFindSlots)

  mainCard.build();
}
  1. The showSettingsPage builds a new card.
function showSettingsPage() {
  const card = CardService.newCardBuilder();
  const cardSection = CardService.newCardSection();

  let content = userStore.getProperty('date');
  let p = CardService.newTextParagraph().setText(content);

  card.addSection(cardSection);
  return card.build();
}

Even when the user changes the date in the home card and navigates to the settings page, the date always shows the default date value.

I'm not sure if the data ins't updating or the card is not updating. I've tried to read the docs on action responses but I don't understand it's suppose to work.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda