Skip to content

Instantly share code, notes, and snippets.

@wendeehsu
Created May 29, 2021 07:50
Show Gist options
  • Save wendeehsu/3138bf64cedbadf38f191601b7362d5a to your computer and use it in GitHub Desktop.
Save wendeehsu/3138bf64cedbadf38f191601b7362d5a to your computer and use it in GitHub Desktop.
var app = SpreadsheetApp.openById("your-sheet-id");
var remindSheet = app.getSheets()[0]; // Get's the fisrt table in the sheet
function checkUser(userId) {
var lastRow = remindSheet.getLastRow(); // the index of the last row
var inDB = -1;
if (lastRow > 0) {
var ids = remindSheet.getSheetValues(1,1,lastRow,1);
/*
In our sheet, we will store all userIds in the first column with no header.
getSheetValues(startRow, startColumn, numRows, numColumns);
return (ids): [['userid1'], ['userid2'], ['userid3']]
*/
for(var i = 0; i < lastRow; i++){
if(userId == ids[i][0]) {
inDB = i+1; // programming list starts with `0`, but Sheet starts with row index `1`
break;
}
}
}
console.log("inDB = ", inDB);
return inDB;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment