Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

Update Google Calendar UI after changing visability setting via Workspace Add-On

I have a very basic Google Workspace Add-on that uses the CalendarApp class to toggle the visabilty of a calendar’s events when a button is pressed, using the setSelected() method

The visabilty toggling works, but the change in only reflected in the UI when the page is refreshed. Toggling the checkbox manually in the UI reflects the change immediately without needing to refresh the page.

Is there a method to replicate this immediate update behaviour via my Workspace Add-On?

A mwe is below.

function onDefaultHomePageOpen() {

  // create button
  var action = CardService.newAction().setFunctionName('toggleCalVis')
  var button = CardService.newTextButton()
    .setText("TOGGLE CAL VIS")
    .setOnClickAction(action)
    .setTextButtonStyle(CardService.TextButtonStyle.FILLED)
  var buttonSet = CardService.newButtonSet().addButton(button)

  // create CardSection
  var section = CardService.newCardSection()
    .addWidget(buttonSet)

  // create card
  var card = CardService.newCardBuilder().addSection(section)

  // call CardBuilder.call() and return card
  return card.build()

}

function toggleCalVis() {
  // fetch calendar with UI name "foo"
  var calendarName = "foo"
  var calendarsByName = CalendarApp.getCalendarsByName(calendarName)
  var namedCalendar = calendarsByName[0]

  // Toggle calendar visabilty in the UI
  if (namedCalendar.isSelected()) {
    namedCalendar.setSelected(false)
  }
  else {
    namedCalendar.setSelected(true)
  }
}
question from:https://stackoverflow.com/questions/65854813/update-google-calendar-ui-after-changing-visability-setting-via-workspace-add-on

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is no way to make a webpage refresh with Google Apps Script

Possible workarounds:

  • From the sidebar, provide users a link that redirects them to the Calendar UI webpage (thus a new, refreshed version of it will be opened)
  • Install a Goole Chrome extension that refreshes the tab in specified intervals

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...