1

This is related to a question I have posted previously.

I have a batch of CSV files that contain a data set obtained from an issue tracker tool. These I've uploaded to google drive and are presented as charts and lists from a google site.

This works reasonable well as all I now have to do is update the files in google drive and the site is automatically updated.

The displayed charts work well, but I want to present the lists as an HTML table (as opposed to an embedded sheet).

An app script seems the most logical way to do this. However, in order to do this, I need to provide the URL of the sheet containing the data to the app script. This is proving to be more difficult than I anticipated.

I attempted passing the data source as a parameter by directly linking the app script URL (xxxxxx/exec?source=yyyy), but the app script gadget in google sites doesn't pass through parameters.

I attempted to embed the script URL (with parameters) within an iframe - as suggested elsewhere, but without any luck.

Has anyone got any suggestions? Thanks.

Dushara
  • 616
  • 1
  • 5
  • 25
  • 1
    Where do you have the script? Is it not within the site? – Robin Gertenbach Jun 12 '17 at 08:46
  • Yes it's within the site. I want to embed the script in several pages, each one pointing to a different sheet in the drive – Dushara Jun 12 '17 at 09:10
  • workarround: from apps script frontend you should be able to get the url of the parent. based on it you can tell where you are on the site. look at window.referer or one of those – Zig Mandel Jun 12 '17 at 14:34
  • @zig Interesting idea. The only issue is, there can be more than one instance of the gadget in one page and figuring out which one invoked the script is going to be error prone :-( – Dushara Jun 12 '17 at 20:29

2 Answers2

2

Google Apps Script gadget can't include parameters in the gadget settings, instead, add the parameters to the links to the Google Site page

https://sites.google.com/sites/mysite/mypage?par1=A&par2=B

Regarding having several instance of the same Google Apps Script gadget that could be a problem. I think that the better way to proceed is to make copies of your script and make a different set of parameters for each one.

Step by step

  1. Create a site
  2. Create a script
  3. Add the gs code

    In this case the code create a template from a file that has a printlet that shows the Hellow World! if the URL parameter message is equal to true, otherwise it you show undefined.

    function doGet(e) {
      var template = HtmlService.createTemplateFromFile('Index');
      if(e.parameter.message === 'true') template.message = 'Hello World!';
      var output = template.evaluate();
      return output;
    }
    
  4. Create a HTML file and add the HTML code

    <!DOCTYPE html>
    <html>
      <head>
        <base target="_top">
      </head>
      <body>
        <p><strong>Message:</strong>&nbsp;<?!=message?></p>
      </body>
    </html>
    
  5. Publish your web app

  6. Create a page
  7. Insert a Google Apps Script gadget
  8. Save the page
  9. Write the page URL and the required parameters in the browser address box or in a link

    https://sites.google.com/a/rubenrivera.mx/ejemplos/posts/1?message=true

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • I attempted what you suggested with: Settings -> Page Settings -> Page URL. However, the URL can only contain -,A-Z,a-z,0-9 so I can't set the parameters for the page (unless I have to do something different?) – Dushara Jun 18 '17 at 23:51
  • @Dushara: I'm sorry for the confusion. The parameters can't be added that way, they could be added on links or other places like UrlFecthApp(url) – Rubén Jun 19 '17 at 03:12
  • So it sounds like there's no way to achieve what I want? – Dushara Jun 19 '17 at 07:17
  • It's possible to pass parameters to google apps script web app that is embedded on a Google Sites page as a gadget. – Rubén Jun 19 '17 at 16:50
2

For apps script web apps embedded in classic google site,querystring parameters work well. Instead do not work if embedded in new google site,and this is a big problem, means that classic web sites that uses querystring cannot be migrated, and soon classic google site will stop working.

Francesco
  • 136
  • 1
  • 4