0

I am trying to create a custom side menu that changes depending on what sheet I am on so the side menu is relevant to what I am on.

I've attempted doing some code to do a tactic where depending on what sheet I am on, the script will choose the correct html file I want it to use.

My issue is with my attempt on function SidebarChooser(), where I've looked at if query's and I can't see what is wrong with mine? (I do intend to add more IF's depending on what you say/advise me to do)

function onOpen() {
  SpreadsheetApp.getUi()
 .createMenu('Sidebar').addItem('Open', 'openSidebar').addToUi();
}

function SidebarChooser() {

  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet()
  var sheet = SpreadsheetApp.getActiveSheet()
  var html = HtmlService.createHtmlOutputFromFile('sidebar');
  if (sheet == '1') {


SpreadsheetApp.getUi().showSidebar(html);

  }

}

function openSidebar() {
var html = HtmlService.createHtmlOutputFromFile('sidebar');
SpreadsheetApp.getUi().showSidebar(html);
}

function Warehouse(){
 var ss=SpreadsheetApp.getActiveSpreadsheet() 
 var s=ss.getSheetByName("GoodsInPlus")
 var row=s.getActiveCell().getRow()
 var column=1
 s.getRange(row, column).activate()
}
function order(){
 var ss=SpreadsheetApp.getActiveSpreadsheet() 
 var s=ss.getSheetByName("2")
 var row=s.getActiveCell().getRow()
 var column=1
 s.getRange(row, column).activate()
}
function stu(){
 var ss=SpreadsheetApp.getActiveSpreadsheet() 
 var s=ss.getSheetByName("UI idea")
 var row=s.getActiveCell().getRow()
 var column=1
 s.getRange(row, column).activate()
}
function merlin(){
 var ss=SpreadsheetApp.getActiveSpreadsheet() 
 var s=ss.getSheetByName("Sheet9")
 var row=s.getActiveCell().getRow()
 var column=1
 s.getRange(row, column).activate()
}

function enterName(name){
 var ss = SpreadsheetApp.getActive()
 var sheet = ss.getSheetByName('1')
 sheet.getRange("A3").setValue(name) 
}

function enterClient(client){
 var ss = SpreadsheetApp.getActive()
 var sheet = ss.getSheetByName('1')
 sheet.getRange("E3").setValue(client)
}

1 Answer 1

1

The problem is that your script is comparing a Sheet object to a literal on the following code line

if (sheet == '1') {

Replace it by

if (sheet.getName() == '1') {
1
  • Thanks a lot. :) I looked at loads of examples and didn't see that! :)
    – Ceebee86
    Commented Aug 1, 2019 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.