I want to selectively show components on the screen based on, if the signed-in user is an existing user or a new user. Just so that you are aware, in my implementation I have a Users sheet that captures email of the user. Therefore, if the user is a new user the email will not be listed there.
I am having a hard time implementing selective visibility of components. Any assistance is appreciated.
I see you’re requiring users to sign in here, what I meant to ask what if you don’t require users to sign in to see the app’s content, so it’s not the case here.
Thank you. Yes, I navigated to the screen in your image above and found that “Sheet” was not pointing to my Users sheet. Does this mean I did not have User profiles enabled?
@Darren_Murphy That was easy, thank you. But realized that due to the privacy settings the email id’s are anonymized. My implementation requires the actual email ID for a subsequent interaction. Any idea how do I achieve it without upgrading my account?
Without going pro, the next best method would be to explicitly ask your users to provide their “real” email addresses, and store them in a separate column in your Users sheet.
You could do it as part of an onboarding process, so it doesn’t appear too odd to your users.
I was having a thought about using a script to replace all the anonymous emails by the real email once the user inputs it.
Let’s say the flow is like this, assuming you already had the anonymous email.
Ask for the user’s real email writing to a user-specific column, then set it to the Sheet column using a button (to avoid triggering the script when the user has not finished the input when you let them write directly to the column).
Once the button is clicked, use the script to find the anonymous email associated with the real email that has just been put in, then find that anonymous email across all Sheets and replace it with the real email.
Here you go. Offered “as is”, with no warranty
Just looking through it, I’d probably do it quite differently now.
That’s always the way, you look at code you wrote in the past and think “what on earth was I smoking back then!?”
function check_user_email_updates() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var user_map = build_user_map();
var sheet = ss.getSheetByName('User Email Updates');
var row = 3;
while (row <= sheet.getLastRow()) {
var data = sheet.getRange(row, 1, 1, 6).getValues();
var status = data[0][5];
if (status == 'Pending') {
var old_email = data[0][1];
var new_email = data[0][2].trim();
var username = user_map[old_email];
console.log(['Updating email address for ', username, old_email, new_email]);
search_and_replace(data[0], data[1]);
var d = new Date();
sheet.getRange(row, 1).setValue(username);
sheet.getRange(row, 5).setValue(d);
sheet.getRange(row, 6).setValue('Completed');
}
row++;
}
sheet.getRange(2, 4, sheet.getLastRow(), 2).setNumberFormat('yyyy-mm-dd hh:mm:ss').setHorizontalAlignment('left');
format_sheet('User Email Updates');
}
function search_and_replace(from, to, sheets) {
sheets = [
'Authorised Emails',
'Payments',
'App:Responses',
'Realtime Pool',
'Pool',
'Private Leaderboards',
'Users',
'Response Archive',
'User Picks',
'Player View Choices',
'App: Logins',
'App: Comments'
];
sheets.forEach(function (sheet) {
process_sheet(sheet, from, to);
});
}
function process_sheet(sheet, from, to) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet);
var values = sheet.getDataRange().getValues();
replace_in_sheet(values, from, to);
sheet.getDataRange().setValues(values);
}
function replace_in_sheet(values, from, to) {
for (var row in values) {
var replaced_values = values[row].map(function (original_value) {
return original_value.toString().replace(from, to);
});
values[row] = replaced_values;
}
}