I have a Google Form for students to input data and I would like an email sent to myself or another person if a specific question has a certain answer. In the email I would like the name of the student that submitted the form to be included in the email. The problem I'm having is the email is only sending the information from Line 2 of my Sheet. (I have line 1 Frozen as headers). I need it to pull from the last line of data entered from the Google Form.
Google Form - https://docs.google.com/forms/d/1r1Tsyfl71zfzgzhs3-_qFB57FcSSEX1zS5BkTgz-ESA/prefill
Google Sheet Data - https://docs.google.com/spreadsheets/d/1P1RD7My91jLSHS9hgEOBPv5oYnfCJQviN6Nzy_cH7Cc/edit?usp=sharing
Here is my script code:
function CheckStudent(e) {
// Fetch the email address
var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2").getRange("B2");
var emailAddress = emailRange.getValue();
// Send Alert Email.
{
var studentData = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 1").getRange("C2");
var studentData = studentData.getValue();
var message = studentData + ' is not doing well today!' // Second column
var subject = 'Student Daily Check Alert';
MailApp.sendEmail(emailAddress, subject, message);
}
}