I'm building a form for students to enter in and I want to Auto input their email address and I'm unsure how to do this. I'm come up with the following but I'm very new to this and may be way off. I'm unsure how to implement it and I'm getting a null response. Do I need a form question which says email ? how do I get the user's email to be recorded but in a hidden way?
function formEnterEmail(e) {
var userEmail = Session.getActiveUser().getEmail();
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = sheet.getLastRow();
// Set the status of the new ticket to 'New'.
// Column F is the Status column
sheet.getRange(lastRow, getColIndexByName("Email")).setValue(userEmail);
function getColIndexByName(colName) {
var sheet = SpreadsheetApp.getActiveSheet();
var numColumns = sheet.getLastColumn();
var row = sheet.getRange(1, 1, 1, numColumns).getValues();
for (i in row[0]) {
var name = row[0][i];
if (name == colName) {
return parseInt(i) + 1;
}
}
return -1;
}
}