Sunday, June 12, 2011

Get URL Parameter from Published Google Apps Script

Google Apps Script getting popular and more popular nowadays. But I found quite hard to see any samples created from independent blogger on the usages. I'd like to take the chance in some areas.

With exposed public google apps script as a service, we need to have a doGet(e) method implemented. To capture url parameter we use this construct :

e.parameter.ParameterName;

for example, explore this script modified from google documentation :

function doGet(e) {
  var app = UiApp.createApplication();
  
  // hello world label
  var helloworldLabel = app.createLabel("I love Apps Script!").setStyleAttribute("fontSize","16px");
  var verticalpanel = app.createVerticalPanel();
  var mybutton = app.createButton(e.parameter.test);
  verticalpanel.add(helloworldLabel);
  verticalpanel.add(mybutton);
  app.add(verticalpanel);
  // add the label to the app container
  //app.add(helloworldLabel);
  
  return app;
}

Notice at line 7, we used URL parameter named "test" as a caption for button element. Exposed this script as service, and try to add url parameter "test" with some value and see the result.

Below is a screenshot of the service execution :

Button Caption comes from URL parameter "test"