I am new to Google App Scripts and have been searching for help with my problem with no luck. I have a google form populating a spreadsheet. Row 1 has the questions and each subsequent row the answers from the form. If a question is answered "Yes" I want to be able to return the question ie. row 1 of that column. I have some code which will send an email if Column 1 (name) is not blank and column 12 (email already sent) is blank. I want to be able to put in the body of the email 'name has answered Yes to the following questions; Q1, Q2 etc.(The headers of each column that have a yes in the searched row) I don't know how to search each row, find the yes answers and return all the column headers.
Here is what I have so far.
// automatically send emails to respondents with their information
function sendEmailv_2() {
// get the spreadsheet information
const ss = SpreadsheetApp.getActiveSpreadsheet();
const TodayFail = ss.getSheetByName('TodayFail');
const data = TodayFail.getDataRange().getValues();
//remove the header
data.shift();
// loop over the rows
data.forEach((row, i) => {
// identify ones not replied to
if (row[12] ==="" && row[1] !=="") {
// get the email address
const name = row[1];
const email = '[email protected]';
// write the email
const subject = name + ' has answered Yes';
const body = `Hi <br><br>
` + name + ` has answered yes to the following questions<br><br>
`;
// send the email
GmailApp.sendEmail(email, subject, '', { htmlBody: body });
// Mark as sent
const d = new Date();
TodayFail.getRange(i + 2, 13).setValue(d);
}
});
}```
viewermode.