3

I'm trying to update the content of the sidebar in a Google Sheet, depending on the current selected cell. My first dummy script is:

function onSelectionChange(e) {
  var ui = SpreadsheetApp.getUi();
  var range = e.range;
  var selectedRow = range.getNumRows();

  var htmlOutput = HtmlService
  .createHtmlOutput('This is row '+selectedRow)
  .setTitle('Title');
  ui.showSidebar(htmlOutput);
}

... and it does nothing, i.e. no sidebar shows ever. I tried to deactivate app script v8, no change.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275

2 Answers2

9

In the current stage, the OnSelectionChange event trigger is used as the simple trigger. In this case, unfortunately, the side bar cannot be used with this event trigger because it is required to authorize. An error of Exception: You do not have permission to call Ui.showSidebar. Required permissions: https://www.googleapis.com/auth/script.container.ui occurs. Unfortunately, this is the current answer.

But, I think that by the future update, when the OnSelectionChange event trigger can be used as the installable trigger, your goal will be able to be achieved.

For this, how about proposing this for the issue tracker as the future request?

Reference:

Tanaike
  • 181,128
  • 11
  • 97
  • 165
2

Let the sidebar update itself

You could let the sidebar update itself depending upon the selected range. As long as the sidebar is active then you have access to all of the features of clientside javascripts including the setInterval function which can use google.script.run to call any server function. Have a function read the current range selected and make modifications to the sidebar based upon those ranges.

Cooper
  • 59,616
  • 6
  • 23
  • 54