Friday, May 10, 2024
107
rated 0 times [  110] [ 3]  / answers: 1 / hits: 30439  / 11 Years ago, thu, march 28, 2013, 12:00:00

Looking for a little help I'm almost there but I know I'm just missing one thing and I have been searching for the answer for awhile.



I have a spread sheet with 1 column that has the first name and the 2nd has the last name, I'm trying to join them and display in full name in the listbox. Right now it populates with the values horizontally letter by letter, with the first columns values and then the second column values. Any help would be appreciated!



function studentBox(e) {
var app = UiApp.getActiveApplication();

var dateSelect = e.parameter.dateList;

var ss = SpreadsheetApp.openById('spreadsheetID');
var sheet = ss.getSheetByName(dateSelect);

var studentList = app.createListBox().setName('studentList').setId('studentList');
var cellList = sheet.getLastRow();
var fName = sheet.getRange(1,1,cellList,1).getValues();
var lName = sheet.getRange(1,2,cellList,1).getValues();
var fullName = (fName+ +lName);


//Add items to the list box
for(var i=0; i<fullName.length; i++){
studentList.addItem(fullName[i]);
}

app.getElementById('grid1').setWidget(1,1,studentList);




return app;

}

More From » google-apps-script

 Answers
47

fName and lName are matrices of values. You can not sum/concatenate them like this. Here the fix:



function studentBox(e) {
var app = UiApp.getActiveApplication();
var dateSelect = e.parameter.dateList;

var ss = SpreadsheetApp.openById('spreadsheetID');
var sheet = ss.getSheetByName(dateSelect);

var studentList = app.createListBox().setName('studentList').setId('studentList');
var cellList = sheet.getLastRow();
var names = sheet.getRange(1,1,cellList,2).getValues(); //getting both first and last names at once

//Add items to the list box
for(var i=0; i<names.length; i++){
studentList.addItem(names[i][0]+' '+names[i][1]);
}

app.getElementById('grid1').setWidget(1,1,studentList);
return app;
}

[#79263] Wednesday, March 27, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hallie

Total Points: 503
Total Questions: 114
Total Answers: 103

Location: Iraq
Member since Fri, Jun 5, 2020
4 Years ago
;