0

I'm programming a Google script for a spreadsheet, and after deploying it as web app, you get an URL (https://script.google.com/macros/s/.../dev).

I would like pass an input parameter in the URL (e.g. (https://script.google.com/macros/s/.../dev/param).

How can I fetch the value of this parameter in the script?

Rubén
  • 34,714
  • 9
  • 70
  • 166
nightcod3r
  • 752
  • 1
  • 7
  • 26
  • To get the current url in JS you can use `document.URL` does google allow you to add extra parameters and still direct to your script? – Quince Oct 29 '14 at 14:39
  • DocumentApp.getActiveDocument().getUrl() would return the URL, but for some reason this is not working, so I can't try with extra parameters. – nightcod3r Oct 29 '14 at 14:50
  • Just to make my point clearer: I'm working with a deployable script, what I'm trying to do is in the scope of a doGet() function. – nightcod3r Oct 29 '14 at 14:51
  • ah is your script sandboxed? not used js on a google spreadsheet before – Quince Oct 29 '14 at 14:51
  • actual just read this http://stackoverflow.com/a/14132977/2737978 which states that you can't get any useful information from the url – Quince Oct 29 '14 at 14:55
  • It is during debugging, but when you deploy it, it can be run from a dedicated URL. Anyway, getUrl() is not working from the sandbox either. – nightcod3r Oct 29 '14 at 14:55
  • That helped, Quice. Now I can get the Url with ScriptApp.getService().getUrl(): https://script.google.com/macros/s/.../dev/. The question now is: how can I try to access this URL parameterizing it? Just adding stuff always returns the message: "Sorry, the file you have requested does not exist." – nightcod3r Oct 29 '14 at 15:01
  • ha, accidentally helpful, the best kind of helpful :) – Quince Oct 29 '14 at 15:03
  • does this help http://stackoverflow.com/questions/22291241/how-to-get-a-url-string-parameter-passed-to-google-apps-script-dogete ? – Quince Oct 29 '14 at 15:08
  • so from the docs there is this information about passing parameters https://developers.google.com/apps-script/guides/ui-service#doGetParams – Quince Oct 29 '14 at 15:11
  • This is really specific to Google-Apps-Script,you should avoid the JavaScript tag... – Serge insas Oct 29 '14 at 16:04

1 Answers1

1

you can add a string at the end of the deployed webapp url, just insert a question mark and separate arguments with &.

example :

the .dev     https://script.google.com/macros/s/AKfycb___vWxs/dev?val=test&otherVal=otherTest

the .exec    https://script.google.com/macros/s/AKfycb___vWxs/exec?val=test&otherVal=otherTest

demo code :

function doGet(e) {
  var valToReturn = ContentService.createTextOutput('the parameters were '+e.parameter.val+'\nand\n'+e.parameter.otherVal).setMimeType(ContentService.MimeType.TEXT);
  return valToReturn;
}

You'll get both parameter values in your browser

Serge insas
  • 45,904
  • 7
  • 105
  • 131