0

I am trying to access the HTTP GET variables in a Google Apps Script (Like PHPs $_GET). I tried several techniques:

  • Plain java script (window.location), which obviously is not supported

  • Googles own Service through SitesApp.getActivePage().getUrl(). Gives me the URL, but without the variable string. On second thought this might make sense.

  • e.parameter.[key] This gives me the following error: TypeError: Cannot read property "parameter" from undefined.

I'd really appreciate some pointers or a working example, thanks.

As per the comment from Srik I tried the following:

function doGet(e) { 
    UserProperties.setProperty("bottleid", e.parameter.id);
    return HtmlService.createTemplateFromFile('showbottledata').evaluate();
}

Which gives me the mentioned TypeError: Cannot read property "parameter" from undefined. (line 2) error.

1 Answer 1

1

First, you need to define your doGet in such a way that it accepts URL parameters

function doGet(e) {
   ....
}

When you call your URL using URL parameters, say parm1=val1, use

var parm1 = e.parameter.parm1 ; 
Sign up to request clarification or add additional context in comments.

2 Comments

ok, thanks. I tried the following: function doGet(e) { UserProperties.setProperty("bottleid", e.parameters.id); return HtmlService.createTemplateFromFile('showbottledata').evaluate(); }, which gives me the mentioned "cannot read property from undefined" error.
Can you give the URL you used to call this script ? I think you may have to use the old URL format as there was a bug opened. I'm not sure of the status of the bug though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.