title: How to show data from Google Sheet To Google Web App based on A Cell Value?
body: <p>I'm trying to show data from Google Sheet to a Google Web App based on a value in the Sheet's cell. So when the value is &quot;YES&quot; then user could see the table data, otherwise it shows rejection alert. To make it clear, here's the flow:</p>
  <ol>
  <li>User submit a code that already in the Google Sheet</li>
  <li>System check if the value in approval column on the code's row is &quot;YES&quot;</li>
  <li>If the value is &quot;YES&quot;, then get the data on the submitted code row in Google Sheet</li>
  <li>Show the data as a table</li>
  </ol>
  <p>I tried with my code, it could alert the rejection if the value is not &quot;YES&quot;, but if the value is &quot;YES&quot; I got an error:</p>
  <blockquote>
  <p>Uncaught TypeError: Cannot read property '10' of null</p>
  </blockquote>
  <p>Is there a way to fix it? Your response will be appreciated :)</p>
  <p>Here's a sample of my Javascript code:</p>
  <pre><code>function submitCode(){
    var code = document.getElementById(&quot;codeInput&quot;).value;
    google.script.run.withSuccessHandler(view).checkTable(code);
  }
  
  function view(array){
    if (typeof array === 'string') {
     alert(array);
    }else{
     var tbody = document.getElementById(&quot;table-body&quot;);
     
     var row = document.createElement(&quot;tr&quot;);
     var col1 = document.createElement(&quot;td&quot;);
     col1.textContent = array[0];
     var col2 = document.createElement(&quot;td&quot;);
     col2.textContent = array[1];
     var col3 = document.createElement(&quot;td&quot;);
     col3.textContent = array[2];
     
     row.appendChild(col1);
     row.appendChild(col2);
     row.appendChild(col3);
    }
  }
  </code></pre>
  <p>Here's a sample of my .gs code:</p>
  <pre><code>function checkTable(code){
    var url =  PropertiesService.getScriptProperties().getProperty('url');
    var ss = SpreadsheetApp.openByUrl(url);
    var ws = ss.getSheetByName(&quot;Sheet1&quot;);
    var data = ws.getRange(5, 1, ws.getLastRow()-1, 4).getValues();
    
    var codeList = data.map(function(r){return r[0].toString(); });
    var position = codeList.indexOf(code); 
    var approval1 = data.map(function(r){return r[1]; });
    var approval2= data.map(function(r){return r[2]; });
    
    if(approval1[position] == &quot;YES&quot;){
      getTable(code);
    }else if(approval2[position] == &quot;YES&quot;){
      getTable(code);
    }else{
      return &quot;Sorry You cannot see the table&quot;;
    }
  }
  
  function getTable(code){
    var url =  PropertiesService.getScriptProperties().getProperty('url');
    var ss = SpreadsheetApp.openByUrl(url);
    var ws = ss.getSheetByName(&quot;Sheet1&quot;);
    var data = ws.getRange(5, 1, ws.getLastRow()-1, 6).getValues();
    
    var codeList = data.map(function(r){return r[0].toString(); });
    var position = codeList.indexOf(code); 
  
    var things1= data.map(function(r){return r[3]; });
    var things2= data.map(function(r){return r[4]; });
    var things3= data.map(function(r){return r[5]; });
  
    var array = [things1[position], things2[position], things3[position]];
  }
  </code></pre>