I'm trying to make a script to put on my google site for my students so that they can look up their login details for mymaths from home. I have a spreadsheet with all their emails which match up to their login details but when they access the page I want the to be able to just see their row. I am using Session.getActiveUser().getEmail() for this and all of my code is below but it is not working!
Any help would be greatly appreciated.
var userID = Session.getActiveUser().getEmail();
var userLogin;
var userPass;
var userName;
var text;
//Function to lookup login and password from email and add to variables
function lookup() {
var spreadsheetKey = '1UftMLEgJPof3533X1Dp2IRqLIJa-70y8m-xnbyfj8ZA';
var sheet = SpreadsheetApp.openById(spreadsheetKey);
var end = SpreadsheetApp.getActiveSheet().getLastRow();
var range = sheet.getRange(1, 0, end, 4);
var values = range.getValues();
for (i = 0; i < values.length; ++i) {
if (values[i][0] == userID) {
text = 'Here are your login details for MyMaths. Now get on with your homework!'
userName = string(values[i][1]);
userLogin = string(values[i][2]);
userPass = string(values[i][3]);
}
else {
text = 'Sorry, but there is an error. You will need to check in your book or ask your teacher for your MyMaths login details.'
}
}
}
//Function to create Userinterface on site page
function doGet() {
var app = UiApp.createApplication();
var panel = app.createAbsolutePanel();
var label = app.createLabel(text);
var table = app.createGrid(2,3);
table.setText(0, 0, 'Name');
table.setText(0, 1, 'Login');
table.setText(0, 2, 'Password');
table.setText(1, 0, userName);
table.setText(1, 1, userLogin);
table.setText(1, 2, userPass);
panel.add(label);
panel.add(table);
app.add(panel);
return app;
}