Adabsiz
Adabsiz

Reputation: 49

Having issue combining multiple scripts

i have the below script which is helping me to embed google form into a google sheet while i have 2 forms in the same sheet and when i put the script both am getting only one selection which is a select button created near HELP called SELECT

i was unable to post the script

while the output only BBB on the selection option,

the sheet is here :

https://docs.google.com/spreadsheets/d/17O84HASI6q17sDH00tKmh_KrHmipUnxGcxafQrarG_c/edit#gid=1543122132

FormAAA: https://docs.google.com/forms/d/1UpG6E08dH3L9YCqCoDpOw2Y4K--7utx1vhpORishxTU/edit FormBBB: https://docs.google.com/forms/d/1_lDDKwaS0EizUdMSoP4FtgVqUe5PImpPBlH8JLItoW0/edit

Looking forwards to your kind help.

Thanks, Adabsiz

Upvotes: 1

Views: 64

Answers (1)

Tanaike
Tanaike

Reputation: 201378

When I saw your sample Spreadsheet and your script, I confirmed that 2 functions of onOpen() and showSidebar() are duplicated in AAA.gs and BBB.gs. I think that this might be the reason of your issue. When you want to put AAA and BBB to the custom menu, how about the following modification?

From:

AAA.gs:

function onOpen() {
 SpreadsheetApp.getUi().createMenu("SELECT NAME").addItem("BBB", "showSidebar").addToUi();
}

function showSidebar() {
 SpreadsheetApp.getUi().showSidebar(HtmlService.createHtmlOutputFromFile("SidebarAAA.html").setTitle("DATA ENTRY"));
}

BBB.gs:

function onOpen() {
 SpreadsheetApp.getUi().createMenu("SELECT NAME").addItem("BBB", "showSidebar").addToUi();
}

function showSidebar() {
 SpreadsheetApp.getUi().showSidebar(HtmlService.createHtmlOutputFromFile("SidebarBBB.html").setTitle("BBB"));
}

To:

AAA.gs:

function onOpen() {
 SpreadsheetApp.getUi().createMenu("SELECT NAME")
 .addItem("AAA", "showSidebar1")
 .addItem("BBB", "showSidebar2")
 .addToUi();
}

function showSidebar1() {
 SpreadsheetApp.getUi().showSidebar(HtmlService.createHtmlOutputFromFile("SidebarAAA.html").setTitle("DATA ENTRY"));
}

function showSidebar2() {
 SpreadsheetApp.getUi().showSidebar(HtmlService.createHtmlOutputFromFile("SidebarBBB.html").setTitle("BBB"));
}

BBB.gs:

In this case, onOpen() and showSidebar() in BBB.gs are not used.

// function onOpen() {
//  SpreadsheetApp.getUi().createMenu("SELECT NAME").addItem("BBB", "showSidebar").addToUi();
// }

// function showSidebar() {
//  SpreadsheetApp.getUi().showSidebar(HtmlService.createHtmlOutputFromFile("SidebarBBB.html").setTitle("BBB"));
// }

Reference:

Added:

About your following additional question,

Hi, appreciate your kind advice and follow up, i did add the suggested script while i choose BBB with its linked sheet as well as AAA with it's linked sheet; unfortunately only one form kept open either AAA or BBB, is there possibility to keep both open with its own sheet. looking forwards to your kind advice. Thanks

Unfortunately, in the current stage, 2 sidebars cannot be opened simultaneously. So in this case, how about the following patterns?

Pattern 1:

In this pattern, SidebarAAA.html is modified as follows. By this, when "AAA" is run, 2 Google forms are opened in a sidebar.

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <iframe src="https://docs.google.com/forms/d/e/1FAIpQLSfixYMtU8QYFC4tUI5XhZDzPsSXcyMNcmnodhG11r6vP6opew/viewform?embedded=true" width="100%" height="900" frameborder="0" marginheight="0" marginwidth="0">Loading…</iframe>

    <iframe src="https://docs.google.com/forms/d/e/1FAIpQLSfZGw4fdkxoec6df-q0VEmbKcBf4Exqg5E-BbEDGvIHzXOiKA/viewform?embedded=true" width="100%" height="900" frameborder="0" marginheight="0" marginwidth="0">Loading…</iframe>

  </body>
</html>

Pattern 2:

In this pattern, SidebarAAA.html and SidebarBBB.html are opened in a sidebar and a dialog, respectively. In this case, please modify showSidebar2() as follows.

function showSidebar2() {
 SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutputFromFile("SidebarBBB.html"), "BBB");
}

Upvotes: 2

Related Questions