I have created a web app for database of my company, the web app is simple, it first asks them to provide their username and a password. Now, I need to find a way how to show all the data that equals only to username that inputted from the login form and getting from sheet data column AF.
Here is i think a problem where need to show all the data.
/**DataTable */
function getAllData() {
var sess = getSession();
var uid = sess.uid;
var range = LoginSheet.getDataRange().createTextFinder(uid).matchEntireCell(true).findAll();
var values = range.getDisplayValues()
Logger.log(values)
return values
}
And here is a sheet where you can work from or copy the information. https://docs.google.com/spreadsheets/d/1zKlemBPAxxbWOSw66rSWM8GPloES1ZTyuTFNZ19PBOE/edit?gid=0#gid=0
Show all the data base on who username will login
Based on the function you posted, createTextFinder(uid).findAll()
only finds individual cells, not entire rows. Also, since findAll()
returns an array of Ranges (not a single range), you can't use getDisplayValues()
directly on it. getDisplayValues()
is a method meant for a single Range of cells. That's why you're encountering issues. I’ve modified the script based on the necessary changes.
Changes
.getDataRange().getValues()
grabs all the data at once.
.filter()
goes through each row and checks if AF == uid
Modified Script
function getAllData() {
var sess = getSession();
var uid = sess.uid;
var range = LoginSheet.getDataRange().getValues();
var header = range.shift();
var userData = range.filter(function(row) {
return row[31] === uid;
});
Logger.log(userData);
return userData;
}
Sample Output
Reference