Invoke app scripts with parameters from classic google site

ε祈祈猫儿з 提交于 2020-01-03 00:28:31

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/44490515/invoke-app-scripts-with-parameters-from-classic-google-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!