使用传统Google网站的参数调用应用程序脚本 [英] Invoke app scripts with parameters from classic google site

查看:88
本文介绍了使用传统Google网站的参数调用应用程序脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与我以前


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.

解决方案

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

这篇关于使用传统Google网站的参数调用应用程序脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆