17

I have a Google Apps Script gadget that is embedded in a Google Sites page. I would like to pass the gadget a page parameter, such that when the page is opened with URL like:

https://sites.google.com/a/mydomain/mysite/mypage?myparameter=1

I can access the value of the page parameter in the Apps Script gadget code like so:

function doGet(e) {
  var app = UiApp.createApplication();
  app.add(app.loadComponent("MyComponent"));
  var myparam = e.parameter.myparameter;    
  return app;    
}

Currently, the value of e.parameter.myparameter is coming back as null. Is there a way to setup my Apps Script to support this? Any approaches are welcome.

Rubén
  • 34,714
  • 9
  • 70
  • 166
DrewCo
  • 954
  • 2
  • 8
  • 20
  • I have the same issue ... works outside of Google sites, but not in them ... – Sam Joseph Sep 12 '12 at 13:46
  • ah, actually it works for me, but I'd much rather have the parameter embedded in the url in the google app script gadget in the site. I'd rather not have to expose the parameters in the site URL, and anyway they will then only be there if users follow a crafted link - I want to be able to specify start up options for a gadget in a particular page ... – Sam Joseph Sep 12 '12 at 13:56

3 Answers3

2

Maybe the link bellow will help you - I have not tried it myself yet...but I will try it out in the next days. http://code.google.com/p/google-apps-script-issues/issues/detail?id=535

Nuno Freitas
  • 983
  • 8
  • 23
java4africa
  • 214
  • 1
  • 3
1

I posted this on the code.google.com page linked in the accepted answer, but the way to have parameters passed through to Apps Script is by adding "https://sites.google.com/feeds" to the Apps Script scope. (See this site for information about how to add explicit scopes.) Once this scope is added, the following works:

in Code.gs:

function doGet(e) {

  var htmlTemplate = HtmlService.createTemplateFromFile("page");
  htmlTemplate.urlParams = e.parameters;
  return htmlTemplate.evaluate();

}

in page.html:

...
<head>
...
<script>urlParams = <?!= JSON.stringify(urlParams) ?>;</script>
</head>
...

urlParams is now available as a variable in your JS code in the following form:

urlParams = { key1: [value1, value2, ...], key2: [value1, value2] }
TobyRush
  • 654
  • 4
  • 20
0

This example describes a parameter as "&name=value" however I have not been able to get it working in either a Google Apps Site, or in a Personal Google Site. (which seem to handle authentication in different ways)

The example seems to work fine when I hard-code the value so maybe I am just not parsing it right or something, I will try to follow up here when I understand this better but I also have not yet found adequate explanations of these features.

One Hypothesis is that Google changed something, I note the menu structure does not seem to match what I assume it use to be since I see many references to a [share] button/menu.

Jason K.
  • 407
  • 4
  • 12