Failed To Show A Row Of Specified Values From Google Sheet To Web App

38 views
Skip to first unread message

R

unread,
Jun 23, 2020, 1:07:04 AM6/23/20
to google-apps-sc...@googlegroups.com
Hey I'm trying to show a row of values from Google Sheet when the user input a specific code number. But the web app shows the letter 'U' 'n' 'a' from the word Unavailable that returned from the .gs code to each of the table column. Is there anything i did wrongly? Your response would be very appreciated. Thank you in advance!

Here's my .html code:

document.getElementById("codeInput").addEventListener("input",getData);
     
function getData(){
     
var code = document.getElementById("codeInput").value;
       
if(code.length === 5){
           google
.script.run.withSuccessHandler(view).getTable(code);  
       
}
     
}
 
     
function view(array){
       
var tbody = document.getElementById("table-body");
   
       
var row = document.createElement("tr");
       
var col1 = document.createElement("td");
        col1
.textContent = array[0];
       
var col2 = document.createElement("td");
        col2
.textContent = array[1];
       
var col3 = document.createElement("td");
        col3
.textContent = array[2];
        row
.appendChild(col1);
        row
.appendChild(col2);
        row
.appendChild(col3);
        tbody
.appendChild(row);
     
}



And here's my .gs code:

   
function getTable(code){
       
var url = "https://docs.google.com/spreadsheets/d/1Nh-CCXayaQ8YFuxV76MGnWiAF2rgcxf5bCJwJWvy_-s/edit#gid=0";
       
var ss = SpreadsheetApp.openByUrl(url);
       
var ws = ss.getSheetByName("IPP Gol I-III");
       
var data = ws.getRange(2, 1, ws.getLastRow()-1, 4).getValues();
 
       
var codeList = data.map(function(r){return r[1]; });
       
var submissionList = data.map(function(r){return r[0]; });
       
var nameList = data.map(function(r){return r[2]; });
       
var emailList = data.map(function(r){return r[3]; });
 
       
var position = codeList.indexOf(code);
 
       
var array = [submissionList[position],nameList[position],emailList[position]];
 
       
if(position > -1){
         
return array;
       
}else{
         
return 'Unavailable';
       
}                    
   
}

Jonathan Butler

unread,
Jun 23, 2020, 11:26:54 AM6/23/20
to google-apps-sc...@googlegroups.com
As a rule of thumb, I would convert everything you send between the client and the server to JSON and convert it back when you receive it. A lot of strings I would send from the client to the server would end up character arrays when they are on the other side. But I have had no loss of data when converting it to JSON and back.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/0b5d80bb-9218-463c-8802-f93145b92dcfo%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages