Last active
December 31, 2018 14:05
-
-
Save phillypb/87db406d41f80f4dbd7d0b63f377a017 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getActiveUser(sheet) { | |
| // get active Tutor email address | |
| var user = Session.getActiveUser().getEmail(); | |
| Logger.log('Active Tutor email is: ' + user); | |
| // get data from Tutors sheet to lookup name from email address | |
| var tutorsSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Tutors'); | |
| var tutorsSheetData = tutorsSheet.getRange(2, 1, 2, 2).getValues(); | |
| // lookup active Tutor email address for corresponding name in Tutors sheet | |
| var tutorName = ''; // create empty variable | |
| if (user == tutorsSheetData[0][0]) { | |
| Logger.log(user + ' matches ' + tutorsSheetData[0][0]); | |
| var tutorName = tutorsSheetData[0][1]; | |
| Logger.log('Tutor name is therefore: ' + tutorName); | |
| } | |
| else if (user == tutorsSheetData[1][0]) { | |
| Logger.log(user + ' matches ' + tutorsSheetData[1][0]); | |
| var tutorName = tutorsSheetData[1][1]; | |
| Logger.log('Tutor name is therefore: ' + tutorName); | |
| } | |
| // get Tutor 1 name from sheet, split just for name | |
| var tutor1Name = sheet.getRange(1, 3).getValue().split(': '); | |
| Logger.log('Tutor 1 name is: ' + tutor1Name[1]); | |
| // get Tutor 2 name from sheet, split just for name | |
| var tutor2Name = sheet.getRange(1, 7).getValue().split(': '); | |
| Logger.log('Tutor 2 name is: ' + tutor2Name[1]); | |
| // find out if user is Tutor 1 or Tutor 2 | |
| if (tutorName == tutor1Name[1]) { | |
| Logger.log(tutorName + ' matches ' + tutor1Name[1]); | |
| var tutorName = 'You are 1'; | |
| } | |
| else if (tutorName == tutor2Name[1]) { | |
| Logger.log(tutorName + ' matches ' + tutor2Name[1]); | |
| var tutorName = 'You are 2'; | |
| } | |
| else { | |
| Logger.log('No one matches'); | |
| } | |
| return tutorName; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment