Onur Yilmaz
Onur Yilmaz

Reputation: 11

Google Apps - Script - Side bar OnOpen/OnInstall function

I'm recently having issues with Google Apps Scripting, I have a script which installed domain wide, which is enables users to make some tasks easier with the side-bar menu however from last week side-bar menu is not popping up anymore. Nothing has been changed on the code.

I did some workaround and tried all possible ways - deauthorization \ authorization, deploying the same code with different name, nothing worked except if the user removes it and adds it to the spreadsheet which they work - it's popping up and working only for that sheet and only for one time.

Can you please advise, how to fix this issue?

Here is my OnInstall and OnOpen functions:

function onInstall(e)
{

onOpen(e)

}

function onOpen(e) {

  var html = HtmlService.createHtmlOutputFromFile('Index')
      .setSandboxMode(HtmlService.SandboxMode.IFRAME)
      .setTitle('BB KING');
  SpreadsheetApp.getUi().showSidebar(html);
}

Thanks in advance.

Edit : Triggers making the side-bar work on simple scripts on spesific spreadsheets, but this method is not working on domain-wide installed add-ons.

Upvotes: 1

Views: 1237

Answers (1)

VLBaindoor
VLBaindoor

Reputation: 324

It should be possible to add a trigger to run the custom function which shows the SideBar.

I have a function like the following in my code that runs on my domain:

function createOnOpenTrigger()
{
    var sheet = SpreadsheetApp.getActiveSpreadsheet();
    // Trigger on open

    ScriptApp.newTrigger(FunctionToRunOnOpen)
              .forSpreadsheet(sheet).onOpen().create();
}

function FunctionToRunOnOpen() 
{
    var html = HtmlService.createHtmlOutputFromFile('Index')
                .setSandboxMode(HtmlService.SandboxMode.IFRAME)
                .setTitle('BB KING');
    SpreadsheetApp.getUi().showSidebar(html);
}

You could then put the createOnOpenTrigger function as an option in your custom menu - to be run only once everytime a copy is made of the entire spreadsheet.

Upvotes: 1

Related Questions