nightcod3r
nightcod3r

Reputation: 792

Parameterizing a script in an URL

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?

Upvotes: 0

Views: 524

Answers (1)

Serge insas
Serge insas

Reputation: 46794

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

Upvotes: 1

Related Questions