Target: Compare list of attendees with list of invitees and send email reminder to those who did not attend.
Method: I am attempting to compare 2 arrays [invited & attended] and return items that are NOT found in each i.e who did not attend training so I can trigger an email reminder.
I've got myself stuck and am mentally blank to the solution. My current code compares the 2 arrays and returns matches. If I set the if statement criteria to if (value[x] !== value[y]) {Logger.log[x]} I am shown rather undesirable output.
Current function as below:
function getAttendees() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Attendees');
var inviteSheet = ss.getSheetByName('Invitees');
var inviteLRow = inviteSheet.getLastRow();
var inviteRange = inviteSheet.getRange("K2:K" + inviteLRow);
var getInvite = inviteRange.getValues();
var attendLRow = sheet.getLastRow();
var getAttendRange = sheet.getRange("A2:A" + attendLRow)
var getAttend = getAttendRange.getValues();
for (var v = 0; v < getAttend.length; v++) {
var vn = v + 2;
for (var e = 0; e < getInvite.length; e++) {
var en = e + 1;
if (getAttend[v].toString() !== getInvite[e].toString()) {
Logger.log(getAttend[v] + " attended training.");
}
}
}
}
If I can return the items not in the "Attendees" array, I can trigger the email function (pretty sure I have that one in the bag already.)
Any help would be greatly appreciated. Will buy digital coffee for whoever fixes it... If I figured it out, I get coffee.
You may filter then out as follows;
Short answer
Google Apps Script compatible version of the script by Redu
Adaptation to the OP case
The script in the short answer works with "simple" arrays, we need to flatten objects to be passed as arguments, in the case of this question getInvite and getAttend by using the following pattern,
Applying the above to the OP code,
Remarks
If you copy the above code, don't forget to copy the code in the short answer section too.
References
Flatten an array of arrays