Question

Given this URL:

https://script.google.com/macros/s/MacroName/dev?theArg="69.28.15.332"

The important part is on the end:

?theArg="69.28.15.332"

I'm trying to pass information to an Apps Script in the URL. Why won't my .gs Google Apps Script function get the value of the string at the end of the URL? This is the doGet(e) function.

function doGet(e){
  var passedInIP = e.parameter.theArg;
  Logger.log(passedInIP);

  if (passedInIP === "69.28.15.332") 
  {
    return HtmlService.createHtmlOutput("<h2>something</h2>")
  }
};

I get this error msg printed in the browser:

The script completed but did not return anything

The Logger.log does log something. It logs [Date Time EDT] "69.28.15.332" and the value is exactly the same in the log, as the value I'm checking for. But the equality test fails.

Was it helpful?

Solution

The argument is passed "as it is", you can test it using a code like below :

function doGet(e){
  var passedInIP = e.parameter.theArg;
  Logger.log(passedInIP);

  if (passedInIP == "69.28.15.332") 
  {
    return HtmlService.createHtmlOutput("<h2>something</h2>")
  }
    return HtmlService.createHtmlOutput(passedInIP)
}; 

This will return "69.28.15.332" including quotes...

So you have 2 possibilities to choose from :

  1. remove the quotes in your url
  2. add quotes in your condition like this '"69.28.15.332"' (single quotes+quotes)

I would choose the first one but for no good reason ;-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top