Friday 4 January 2019

Student Feedback system - get active spreadsheet user

The following Google Apps Script code was developed to determine if a tutor accessing a Google sheet was tutor 1 or 2, which would later display options on a form they could edit. The tool achieves this by getting their email address from the active session, looking up their name in a table, then checking this against a particular column. The result is a variable set to You are 1 or You are 2 which I then used in an if statement for the rest of the script.

We start by getting the email address from the active tutor ('getActiveUser') logged into the spreadsheet. We then get details from the Tutors sheet (which was populated during the Bulk add Drive permissions post). Now the relevant tutor name can be acquired from an email address if match (see Lookup email address post for further details). Back on the Group Feedback tab it is necessary to 'split' the Tutor 1: and Tutor 2: strings in turn so that we just have the names (so John Smith rather than Tutor 1: John Smith as in my example). A simple if can now determine whether there is a match and return the tutorName variable.

Get active spreadsheet user.xlsx

No comments:

Post a Comment