title: How to call Google App Script from a web app?
body: <p><strong>Task:</strong> Open a google spreadsheet in web app, select a portion of values in that spreadsheet and on clicking a button on my web app, I should get selected values.</p>
  
  <p>I tried to this through Google App script (following code). This works fine when I run the script from online having spreadsheet opened in another tab.</p>
  
  <pre><code>      function doGet() 
        {
          var sheet = SpreadsheetApp.getActiveSheet();
          var data = sheet.getActiveRange().getValues();
          //Logger.log(data.length);
          for (var i = 0; i &lt; data.length; i++) 
          {
            var output = HtmlService.createHtmlOutput("Product name: " + data[i][0] + ", Quantity:" + data[i][1]);  
          }
  
         //Logger.log(output.getContent());
        return HtmlService.createHtmlOutput(output);
        };
  </code></pre>
  
  <p>But when I try to deploy the script as web app and take the published url as the action for my form when I click button in my web app. Its not working.</p>
  
  <pre><code>  &lt;form action="https://script.google.com/macros/...." method="get"&gt;
  &lt;input type="submit" value="call"&gt;
    &lt;/form&gt;
  </code></pre>
  
  <p>I added the above code in my webapp, where the spreadsheet is opened and displayed!</p>
  
  <p>Now, when I click the "call" button from my web app it throws error "TypeError: Cannot call method "getActiveRange" of null."</p>
  
  <p>How do I fix this?</p>