1

I am trying to complete a form created in google app script web app via URL with the intention to display the field but be inactive and a UUID for form submit.

In web app testing the form is completed by URL eg: https://script.google.com/macros/s/AKfycbwam4eZHPrs2ooVQLzJZgMcFb9gfXC2OPSq8f7Xkp9z/dev?fn=bob filling "bob" into field "fn".

However to remove googles "This application was created by another user, not by Google.Terms of Service" we put the web app in and iframe or link in google sites. This throws a spanner in the works.

Any advise will be much appreciated


    function doGet() {
      return HtmlService.createTemplateFromFile("page").evaluate().setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
    }
    
    
    function userClicked(userInfo){
     
      const url = "https://docs.google.com/spreadsheets/d/1-7D4bXhm1Yx0ekRUmrwr8fTsdQ0dLtMI4gYG-THPUdk/edit#gid=0";
      const ss = SpreadsheetApp.openByUrl(url);
      const ws = ss.getSheetByName("data");
     
     ws.appendRow([userInfo.firstName,userInfo.lastName,userInfo.app,new Date()])
    
     // Logger.log(name + " Clicked The Button");
    
    }
    
    function include(filename){
      return HtmlService.createHtmlOutputFromFile(filename).getContent();
    
    }
    <script>

        document.addEventListener('DOMContentLoaded', function() {
          var elems = document.querySelectorAll('select');
          var instances = M.FormSelect.init(elems);
        });

      document.getElementById("btn").addEventListener("click",doStuff);

      function doStuff(){

        const userInfo = {};

        userInfo.firstName = document.getElementById("fn").value;
        userInfo.lastName = document.getElementById("ln").value;
        userInfo.app = document.getElementById("app").value;

        google.script.run.userClicked(userInfo);

        document.getElementById("fn").value = "";
        document.getElementById("ln").value = "";

        var myApp = document.getElementById("app");
        myApp.selectedIndex = 0;
        M.FormSelect.init(myApp);

      }


    </script>

      <script>
        google.script.url.getLocation(function(location){

          document.getElementById('fn').value = location.parameters.fn[0]
          document.getElementById('ln').value = location.parameters.ln[0]
        })

        </script>
Rubén
  • 34,714
  • 9
  • 70
  • 166

1 Answers1

1

Unfortunately there is no way to pass a query string parameter into a Google Apps Script web app embedded in Google Sites but this might be done by using client-side JavaScript on a "regular" web page.

Note: Use the /exec URL, not the /dev one.

<body onload="loadIframe();">
   
    <div id="content">
        <iframe width="100%" height="100%" frameborder="0"></iframe>
    </div>
    <script>
    function loadIframe(){
        const url = "put_here_your_web_app_url" + window.location.search;
        document.querySelector('iframe').src = url;
    }
    </script>
</body>

Related

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • Brilliant - I had to figure out to use the page.html instead of the code.gs URL reference but eventually. Working as wanted. Many Thanks – Matthew Gibbon Jul 24 '22 at 08:05