I am creating a bathroom sign out sheet for my middle school students. I have created a Google App Script that Collects students names from a dropdown box and then logs the date and time. Everything seems to work great except when 500 students have access to the sheet at the same time. If a student selects their name it can possibly change before the script can be run. I would like to replace the dropdown box with a script that will automatically grab their Google User Name. Is there anyway this can be done? I am a novice programmer and tend to get things to work by tinkering around with it, but this seems to be above my head. Here is the Google Sheet and the Script is attached as well. Thanks in advance
function clockIn()
{
//DEFINE ALL ACTIVE SHEETS
var ss = SpreadsheetApp.getActiveSpreadsheet();
//DEFINE MAIN SHEET
var mainSheet = ss.getSheetByName("DATASHEET");
//LAST ROW ON MAIN SHEET
var lastRow = mainSheet.getLastRow();
for (var j = 5; j <= lastRow; j )
{
// CHECK CLOCK IN
if(mainSheet.getRange('B1:B1').getValue() == mainSheet.getRange(j, 1).getValue() && mainSheet.getRange(j,3).getValue() == '')
{
Browser.msgBox("⚠️ You are Already Signed Out","Please Click the Returning to Classroom Button and then Try Again!",Browser.Buttons.OK);
return;
}
}
//_________________________________________________________________________________________________________________________________________________//
// ADD CLOCK IN RECORD
mainSheet.getRange(lastRow 1,1).setValue(mainSheet.getRange('B1:B1').getValue()).setFontSize(12);
mainSheet.getRange(lastRow 1,2).setValue(new Date()).setNumberFormat("MM/dd/yyyy hh:mm:ss A/P").setHorizontalAlignment("left").setFontSize(12);
//CLEARCONTENTS
{
var sheet = ss.getSheetByName("MAIN");
sheet.getRange('B1:B2').clearContent();
}
if (mainSheet.getRange('B1:B1').getValue() == mainSheet.getRange('B1:B1').getValue() && mainSheet.getRange(j,3).getValue() == '')
{
SpreadsheetApp.getUi().alert("⏰ Please Hurry Back! ⏰","Your Teacher is Waiting",SpreadsheetApp.getUi().ButtonSet.OK);
}
}
//_________________________________________________________________________________________________________________________________________________//
function clockOut() {
//DEFINE ALL ACTIVE SHEETS
var ss = SpreadsheetApp.getActiveSpreadsheet();
//DEFINE MAIN SHEET
var mainSheet = ss.getSheetByName("DATASHEET");
//LAST ROW ON MAIN SHEET
var lastRow = mainSheet.getLastRow();
var foundRecord = false;
for (var j = 5; j <= lastRow; j )
{
// FIND CLOCK IN RECORD
if(mainSheet.getRange('B1:B1').getValue() == mainSheet.getRange(j, 1).getValue() && mainSheet.getRange(j,3).getValue() == '')
{
SpreadsheetApp.getUi().alert("