/**
* @OnlyCurrentDoc
*/
function appendDailyData() {
//Get the list of valid emails
var emails = [];
registerSheet = SpreadsheetApp.getActive().getSheetByName("Register");
lastRow = registerSheet.getLastRow();
emailData = registerSheet.getRange(1, 1, lastRow, 1).getValues();
emailData.forEach(function(row) {
emails.push(row[0]);
})
//Get the list of available dates as text strings
var dates = [];
registerSheet = SpreadsheetApp.getActive().getSheetByName("Register");
lastColumn = registerSheet.getLastColumn();
datesData = registerSheet.getRange(1, 1, 1, lastColumn).getValues();
for (var row in datesData) {
for (var col in datesData[row]) {
dates.push(String(datesData[row][col]));
}
}
console.log(dates);
//Get the new data from GAMData
var GAMrows = [];
GAMSheet = SpreadsheetApp.getActive().getSheetByName("GAMData");
lastRow = GAMSheet.getLastRow();
GAMData = GAMSheet.getRange(1, 1, lastRow, 3).getValues();
//For each row in GAMData, check if it matches an email in the register tab. If so, get the row in the register to update.
numRows=0;
rowToUpdate=0;
columnToUpdate=0;
GAMData.forEach(function(row) {
numRows+=1;
if (emails.includes(row[0])) {
//Get the row in the register.
rowToUpdate = emails.indexOf(row[0])+1;
//Next check if it matches a date in row 1 of the register.
//var theDate = String(row[1]);
var theDate = String(row[2]).substring(0,10); //This takes the date from the last interaction rather than the date column
console.log(theDate);
if (dates.includes(theDate)) {
//Get the column in the register
columnToUpdate = dates.indexOf(theDate)+1;
//If both are matched then update the cell with the time accessed.
if (theDate == row[2].substring(0,10)) {
registerSheet.getRange(rowToUpdate,columnToUpdate).setValue(row[2].substring(11,16));
}
}
}
else {
columnToUpdate="None"
};
}) //End of FOR loop
} //End of function