Hey there I am trying to build a webapp that source data from a Google Sheet structured like this:
| email | name | SSN | city | more info... |
I would like to take this info (based on user's mail) and build an object:
let personalData = {
name: "";
ssn: "";
city: ""; }
to be passed to the client side and use personalData.name
to change the user name in the sidebar (for example).
In home.html I have a sidenav built around this
<ul>
<li>
<div class="user-view">
<span id="name"> name </span>
<span> email </span>
</div>
[...]
+home-js
document.addEventListener('DOMContentLoaded', function() {
google.script.run.withSuccessHandler(updateUsrInfo).getPersonalData(); }
function updateUsrInfo(data) {
document.getElementById("name").value = data.name; } // .innerText? .appendChild?
+code.gs
function getPersonalData() {
let ss = SpreadsheetApp.openByUrl(url)
let ws = ss.getSheetByName("sheet");
let data = ws.getDataRange().getValues();
let user = {};
data.forEach( function (r) {
if (r[0] === Session.getEffectiveUser().getEmail() ) {
user.email = r[0];
user.name = r[1];
[...]
}
return user;
}
I am unable to change the text of <span id="name">
. I used ".value" 'cause I used that method to change the text in a input form (unable to reproduce it anyway). What am I doing wrong?