multiple lists from different spreadsheet

71 views
Skip to first unread message

Zoek het uit!

unread,
Jul 20, 2019, 10:45:02 AM7/20/19
to google-apps-sc...@googlegroups.com

Hello,

I have been following the tutorials of  "Learn Google Spreadsheets" (https://www.youtube.com/channel/UC8p19gUXJYTsUPEpusHgteQ) and are stuck with the following.


In my html file i have got a select/dropdown menu that gets the values from a spreadsheet. Thats working fine-) .However, i would like to
add another dropdowm that gets his values from another spreadsheet.  I. m tryning to do that but keep getting the same values as from the other dropdown. 

This is what i have in mij gs file:

function doGet(e){
  
  //views
  Route.path("form",loadForm); 
  Route.path("table",loadTable); 
  Route.path("analyse",loadAnalyse);
;
   
  
  if(Route[e.parameters.v]) {
      return Route[e.parameters.v]();
  } else{
  return render ("home");
  }
  
  
}


function loadForm() {
  
  var ss = SpreadsheetApp.openByUrl(url);
  var ws =ss.getSheetByName("Options");
  var list =ws.getRange(1,1,ws.getRange("A2").getDataRegion().getLastRow(),1).getValues()
  var htmlListArray = list.map(function(r) {return '<option>' + r[0]  +   '</option>' ;  }).join('');  
  
  return render("page",{list: htmlListArray});

}

function loadAnalyse() {
  
  var ss = SpreadsheetApp.openByUrl(url);
  var ws =ss.getSheetByName("Options2");
  var list =ws.getRange(1,1,ws.getRange("A2").getDataRegion().getLastRow(),1).getValues()
  var htmlListArray = list.map(function(r) {return '<option>' + r[0]  +   '</option>' ;  }).join('');  
  
  return render("analyse",{list: htmlListArray});
 

Is it correct that I have to give the list a different name? If so, can you help me with this?

Thank you in advance

Clark Lind

unread,
Jul 20, 2019, 7:19:56 PM7/20/19
to Google Apps Script Community
I love his channel and support him on Patreon.  For your code, I think you need another route identifier. 
loadForm = e.parameter 
loadTable = e.parameter.v
loadAnalysis = ??   maybe e.parameter.a   [for 'analysis'] 

Then instead of an 'if' statement, use a 'switch' as you build it out more and more.

instead of this:

 if(Route[e.parameters.v]) {
      return Route[e.parameters.v]();
  } else{
  return render ("home");
  }

use something like this (this is untested, just the concept):
switch(e.parameters) {
  case v:
    return Route[e.parameters.v]();
    break;
  case a:
    return Route[e.parameters.a]();
    break;
  default:
    return render ("home");
}

Hope that gives you a place to start! 

Zoek het uit!

unread,
Jul 21, 2019, 8:22:17 AM7/21/19
to Google Apps Script Community
Hello and thank you for you answer. 

Now im getting a "v"is not defined error. -(

----------------------------------------------------------------------------------------------------------------------------------
function doGet(e){
  
 // views
  Route.path("form",loadForm); 
  Route.path("table",loadTable); 
  Route.path("analyse",loadAnalyse);
  
   loadForm = e.parameter 
   loadTable = e.parameter.v
   loadAnalyse = e.parameter.a   
    

switch(e.parameters) {
  case v:
    return Route[e.parameters.v]();
    break;
  case a:
    return Route[e.parameters.a]();
    break;
  default:
    return render ("analyse");

   }
  
  
}


function loadForm() {
  
  var ss = SpreadsheetApp.openByUrl(url);
  var ws =ss.getSheetByName("Options");
  var list =ws.getRange(1,1,ws.getRange("A2").getDataRegion().getLastRow(),1).getValues()
  var htmlListArray = list.map(function(r) {return '<option>' + r[0]  +   '</option>' ;  }).join('');  
  
  return render("page",{list: htmlListArray});
 
}
function loadAnalyse() {
  
  var ss = SpreadsheetApp.openByUrl(url);
  var ws =ss.getSheetByName("Options2");
  var list =ws.getRange(1,1,ws.getRange("A2").getDataRegion().getLastRow(),1).getValues()
  var htmlListArray = list.map(function(r) {return '<option>' + r[0]  +   '</option>' ;  }).join('');  
  
  return render("page",{list: htmlListArray});
 

 

}


function loadTable() {
  
 
  return render("table");
}
-----------------------------------------------------------------------------------------------------


Op zaterdag 20 juli 2019 16:45:02 UTC+2 schreef Zoek het uit!:

Zoek het uit!

unread,
Jul 22, 2019, 5:54:43 AM7/22/19
to Google Apps Script Community
So far i've got two dropdown lists in a single view. When i change the spreadsheet to anoher one, the values of both of the dropdowns are the same, which is logical.

Is there a way to assign the id of the dropdown to a spreadsheet ?


Op zaterdag 20 juli 2019 16:45:02 UTC+2 schreef Zoek het uit!:

Clark Lind

unread,
Jul 22, 2019, 7:31:00 AM7/22/19
to Google Apps Script Community
Can you share your sheet or make/share a sanitized copy?

Zoek het uit!

unread,
Jul 22, 2019, 7:33:08 AM7/22/19
to google-apps-sc...@googlegroups.com
I just shared it.

Op ma 22 jul. 2019 om 13:31 schreef Clark Lind <cwl...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/d68580d1-0988-47d6-a1fd-1f35f6fc26e9%40googlegroups.com.

Clark Lind

unread,
Jul 22, 2019, 9:08:30 AM7/22/19
to Google Apps Script Community
Looks like I misled you, I apologize.  Everything I said about adding "a" was wrong since you are using "v" for everything and simply changing the value of v.
I just shared it.

To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

Zoek het uit!

unread,
Jul 22, 2019, 9:20:35 AM7/22/19
to Google Apps Script Community
oké, doesn't matter-),

I'm not a programmer, but it seems logic to me to add an id to the function that gets the values from the sheet to the id in thid case the selection box. 

Are am i thinking wrong-)

Op maandag 22 juli 2019 15:08:30 UTC+2 schreef cwlind:

Clark Lind

unread,
Jul 22, 2019, 9:28:45 AM7/22/19
to Google Apps Script Community
I believe it is working. :)

Zoek het uit!

unread,
Jul 22, 2019, 9:30:48 AM7/22/19
to Google Apps Script Community
That is right, but that worked already. I ment the both dropdowns in the analyse form.  I want to show the values from options in the app select/dropdown(the first one and called id= app) and in the second one(id =app1) i want the values of options 2.

Op maandag 22 juli 2019 15:28:45 UTC+2 schreef cwlind:

Clark Lind

unread,
Jul 22, 2019, 1:40:03 PM7/22/19
to google-apps-sc...@googlegroups.com
Ok, I got it working I think.  First dropdown pulls from options tab, and second dropdown pulls from options2 tab:
image.png
image.png

I just shared it.

To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/sCZSp8wLY3A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/73a27362-3eb7-492c-ba63-69f916684569%40googlegroups.com.

Zoek het uit!

unread,
Jul 22, 2019, 2:52:24 PM7/22/19
to Google Apps Script Community
It works perfect.-) I am very grateful that it worked out. The trick is to add a list to existing list am i right?

Op maandag 22 juli 2019 19:40:03 UTC+2 schreef cwlind:
I just shared it.

To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/sCZSp8wLY3A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-community+unsub...@googlegroups.com.

Clark Lind

unread,
Jul 22, 2019, 3:04:03 PM7/22/19
to google-apps-sc...@googlegroups.com
Yes. :)  Since each list populates a separate dropdown on the page, you pass all the lists at one time ( in code.gs:  return render("analyse",{list: htmlListArray, list1: htmlListArray1});  ), and call each one separately,
in  analyse.html
<?!=list; ?>
<?!=list1; ?>

Hope that makes sense :) 
Best,



I just shared it.

To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/sCZSp8wLY3A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/sCZSp8wLY3A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/38ec0e23-0706-48cc-8d21-2203841889ed%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages