I want the user who has Viewer access in the google sheets can add and edit records in the Web App. While maintaning my deployment settings like this:
Execute as: User accessing the web app
Who has access: Anyone with Google account
Because they are just able to access the web app but when making changes in the records there, they are getting an error like “3622554558-mae_html_…tml_user__fil.js:64 Uncaught” and the changes are not applied. While the users who has Editor access in the google sheets can add and edit records in the Web App
Please help me with my codes to achieve my goal
Code.gs
function doGet(e) {
return handleRequest(e);
}
function loadIndex(e) {
return handleRequest(e);
}
function handleRequest(e) {
// Check if the event object e is defined and has parameters
var page = (e && e.parameter) ? e.parameter.page || 'index' : 'index'; // Default to 'index' if no page is specified or e is undefined
try {
var userEmail = Session.getActiveUser().getEmail();
Logger.log("User Email from Session: " + userEmail); // Debugging line
if (!userEmail) {
return HtmlService.createHtmlOutput("Could not retrieve user email. Please ensure you are logged in.");
}
// Directly return the page since users are managed by Google Sheets permissions
Logger.log("User is authorized: " + userEmail); // Debugging line
return HtmlService.createTemplateFromFile(page).evaluate();
} catch (err) {
Logger.log("Error in handleRequest: " + err.toString()); // Log the error
return HtmlService.createHtmlOutput("An error occurred: " + err.toString());
}
}
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename).getContent();
}
Anonymous is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.