-1

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?

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • 1
    If you haven't done yet, implement a way to verify that the object is to pass to the client side has the expected values. If you need further help, please add a [mcve]. – Rubén Oct 03 '22 at 21:15
  • @Rubén in updateUsrInfo() I placed a Logger.log(data) and it seems to pass correctly (but I am tired right now so I'll post an update tomorrow) – Lorenzo Oct 03 '22 at 21:23
  • https://stackoverflow.com/questions/1358810/how-do-i-change-the-text-of-a-span-element-using-javascript – Cooper Oct 04 '22 at 14:02

1 Answers1

1

Make sure you are not passing any Date object to the client. Also try changing:

document.getElementById("name").value = data.name;

To

document.getElementById("name").innerHTML = data.name;
TheWizEd
  • 7,517
  • 2
  • 11
  • 19