0
votes

I'm using the code below to trigger a bar code scanner android app from the android chrome browser using a appscript page and eventually get the scanned code into a html field in my appscript app.

So far the scanner gets activated, scans the QR code but than it returns to the url with the QR code at the end:

https://script.google.com/macros/s/AKfycbw6WjNPEKuY73l_c6_2DfF75FUL3IVX7hEP-QuOIEGJIJ7j2hDQ/exec?page=desc?QRcode=364

I get this below error :

No HTML file named desc?QRcode=364 was found. (line 44, file "MainFile", project "Code")

And line 44 of my MainFile is: return HtmlService.createTemplateFromFile(e.parameter['page']).evaluate();

364 is the QR scanned code.

I need to get the QR code into the form field.

desc.html

    <!DOCTYPE html>
     <html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <a href="zxing://scan/?ret=https://script.google.com/macros/s/AKfycbw6WjNPEKuY73l_c6_2DfF75FUL3IVX7hEP-QuOIEGJIJ7j2hDQ/exec?page=desc?QRcode={code}">Scan</a>


                  <input id="user" value="">


    </body>
    </html>








        <script>

       //retriave url value
         google.script.url.getLocation(function(location) {
    document.getElementById("user").value = location.parameters.QRcode[0];
  });

        </script>

    serverSide.gs

    function doGet(e) {
    Logger.log( Utilities.jsonStringify(e) );
    if (!e.parameter.page) {
    // When no specific page requested, return "home page"
     return 
    HtmlService.createTemplateFromFile('SessionLoginHTML').evaluate();
      }           
    // else, use page parameter to pick an html file from the script
    return 
    HtmlService.createTemplateFromFile(e.parameter['page']).evaluate();
     }
1
Should ?QRcode={code} be &QRcode={code}? - Rafa Guillermo
Show server side code - TheMaster
You are correct but here is where the problem is, when I change ? to & the url stops returning the QRcode part although it does reloads the page(without the QRcode={code}`) - user2916405
@TheMaster I have added the server side code to the list above. I have also change the approach on retrieving the value . - user2916405
As @Rafa says, it should be &, but it's unclear what your new problem is. - TheMaster

1 Answers

1
votes

OK... The only way I got this to work was to not include the html file name (?page=desc) in the url and instead just place the ?QRcode={CODE} in it's place instead. It may have something to do with the ? part I think that the scanner is programmed to see it as the markup point to insert the scanned code. Not sure, would be nice to find out.

Below is the code that works.

  <!DOCTYPE html>
   <html lang="en">
   <head>
       <meta charset="utf-8" />
      <title></title>
     </head>
     <body>
           <a href="zxing://scan/? 
   ret=https://script.google.com/macros/s/AKfycbxttv6npTySORy7Bm0xMu1sjGm- 
   XiUixl8GX5m2i1bMycEKFCTr/exec?QRcode={CODE}">Scan</a>


              <input id="user" value="">


    <script>

      google.script.url.getLocation(function(location) {
      document.getElementById("user").value = location.parameters.QRcode[0];
      });

         </script>


    </body>
    </html>